Reply
Redirect www to no www, all directories?
Old 11-03-2007, 03:48 AM Redirect www to no www, all directories?
Experienced Talker

Posts: 37
Name: Larry K
My web site at http://example.org/ runs on an Apache server on my Web host, on Linux, and I develop using Apache on Windows, configured with Perl, PHP and server side includes, just like my host. Using non-Microsoft software, I can write and directly save .htaccess to my computer and upload it to my host via ftp, so I avoid the typical Windows limitations in that regard.

I have placed a redirect for www.example.org to be sent to http://example.org/, in my .htaccess in the host Web root. And because in most branches I do not have any .htaccess in my subdirectories, the nearest .htaccess is in the root, and affects the entire branch.

It tests out for my start page, because if I go to www.example.org (no slash), it becomes http://example.org/.
Similarly www.example.org/ becomes http://example.org/.

Now the rub: If I go to any subdirectory, as with a call to http://www.example.org/ve/, it goes to http://www.example.org/ve/, or a call to http://example.org/ve (no slash), also goes to http://www.example.org/ve/.
And if I leave the slash off the end, and go to http://example.org/ve, it goes to http://www.example.org/ve/.

I have sat here reading articles and searching Google, but am having a bit of a time comprehending the punctuation symbols in the code and what possibly I could add to to the .htaccess file to include all my branch pages as well as the root.

Since the page runs on server side includes, If I need to, I could maybe develop a Perl equivalent to the php solution that is added to every page, and use a <!--#exec cgi="/cgi-bin/filename.cgi"--> at the verty top of every page. Otherwise I would have to convert everything from ssi to using php includes, of which I am not as well versed.
By the way, I added a base href tag, which had no impact on the issue, declaring <base href="http://example.org/" />
Thank you all in advance.
--Larry
Follows is the entire rewrite engine code from the server root .htaccess:
Code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.org$1 [NC]
RewriteRule ^(.*)$ http://example.org/$1 [R=301,NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?example\.org/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /image/nohotlink.jpe [L]
L a r r y is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 11-04-2007, 05:26 AM Re: Redirect www to no www, all directories?
Experienced Talker

Posts: 37
Name: Larry K
Hello again:
I have found the culprit.
I discovered that when I create a clean directory called foo, and put an index page in it, I can address it as www.example.org/foo and have it show up as http://example.org/foo/.

However, I had some directories which housed a subdomain. So I created a bunch of these, such that if you remember my name, example.org, you can insert stuff in front of it, like for a page filled with selected links to the FCC web site, I would set up fcc.example.org, it would be in the /fcc/ folder on my site. It was not accessible as example.org/fcc/, however, only as fcc.example.org/.

Trying to use server side includes and have a site-wide look and feel across subdomains required that I set up a set of includes in every subdomain, change every one of them to make a single change to the look of the site, a pain in the neck.

Use of <base href="example.org/" /> would cause all of my local page links to go to the home page of the site instead of this page. So I had to code every link as http://whatever.example.org/#reference to make stuff work. Working from a template, I had toi remember to recode all the links. A royal pain in the tush that was.

So I redirected foo.example.org/ to example.org/foo/. At least now I had a single set of server sides for the entire site. And I did not need a base href.
However, in each of these directories resided an htaccess file containing the likes of this:

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^wx.example.org$ [OR]
RewriteCond %{HTTP_HOST} ^www.wx.example.org$
RewriteRule ^(.*)$ http://newweb.wrh.example.com/psr/general/skywarn/$1 [R=301,L]
And in each of these directories, even though the redirection was on and I could address as either foo.example.org or as example.org/foo/, this code negated my effort to stamp out www.example.org/foo/.
Oh I tried to add RewriteCond %{HTTP_HOST} ^www.example.org/foo$ [OR]
ahead of the rules up there, it was ignored. At one time I came up with a
200!
Internal Server Error!
from my 500! page. Obviously, I had things so bottled up that I developed a 500 code, displayed the page, which then reported 200 OK.

Oh, and I had to find out how to flush Firefox cache before I could get rid of the internal server error, because Opera brought up the page without an error in the meantime.

I went to cpanel, did away with all on-site subdomains, and then went to my ftp and gassed all the redirection htaccess files. My folders now all work just fine.

I hope this may be of some help to others. As an aside,
I use htaccess files in Windows xp, running Apache server on my localhost, and I must say they are easy to work with if I know what to put in them!

First of all, do not try to rename a file in Windows Explorer (your desktop, My Computer). They "require" a filename in front of the extension.
Replace Notepad with MetaPad, or any number of other Notepad replacements. MetaPad will let you name a file as .htaccess, and it is ready to go. Notepad will also, if you jump through its hoops. Every time either place the name in quotes or select All file types.

Arachnophilia 4.0 for Windows (I never got used to the Java version's look and feel) also will handle the .htaccess naming issue. And I am sure there are better editors out there, but I have heavily modified this one with regard to templates and toolbars to write xhtml strict code with it.
Kind regards, and thank you for putting up with my question.
Larry
L a r r y is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Redirect www to no www, all directories?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12842 seconds with 12 queries