Forum Moderators: phranque
My sites are hosted on Apache virtual hosting server, my add-on sites are getting listed in SE's as http://example.com, what i am looking for, is making modifications in .htaccess file so they appear as http://www.example.com
I read about it and found that i have to use variations of following code, but i am not able to figure it out.
# And for a site running on port 80
RewriteCond %{HTTP_HOST}!^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST}!^$
RewriteRule ^/(.*) [fully.qualified.domain.name...] [L,R]
# If HTTP_HOST request header is non-blank
RewriteCond %{HTTP_HOST} .
# AND HTTP_HOST request header does NOT contain canonical (preferred) domain name
RewriteCond %{HTTP_HOST} !^www\.example\.com
# Then issue 301-moved permanently to same 'page' on canonical domain
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
The only time the redirects to home do NOT happen is when the desired file is top-level (/public_html/file.html).
I tried the numeric equivalent with the same results: top-level->A-OK; directory-level(s)->home:
RewriteCond %{HTTP_HOST} ^123\.456\.78\.9
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
From a similar thread [webmasterworld.com] about redirecting 'dot-slashers', again the same results:
# Handle www.example.com/. variants
RewriteRule ^\. http://www.example.com/ [R=301,L]
#
# Handle www.example.com./ variants
RewriteCond %{HTTP_HOST} ^www\.example\.com\.
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
I thought the lines might be conflicting with other Conds/Rules but my error_log is A-OK and the directory-level redirects do happen -- just not to the right places.
Any ideas? Is there an AWOL / or $ in the Cond statements? I'd love for people to be able to go to the intended page, just with the preferred domain name.
As always, thanks in advance for your expertise, and patience! :)
Kind of rushing through today...
You may need to add
RewriteOptions inherit
Also, it might be a RewriteBase problem -- check the server error log on those failed attempts.
It could also be an 'Alias' problem. If those subdirs are Aliased away from you in httpd.conf, then your top-level .htaccess won't run.
Jim
1.) "RewriteOptions inherit" <-- Been there, done that (ages ago in all directories having an .htaccess to make sure unauthorized bots don't acccess any contents via external links).
2.) RewriteBase: None specified that I know of. Also, no RewriteMaps.
3.) Aliases: The httpd.conf directives look routine and have to do with icons (Alias /icons/ "/var/www/icons/") and cgi-bin (ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"). On a related note -- I don't have any Sym Links controlling any directories, just the occasional CGI, etc.
4.) error_log (this domain's; Combined format): Clear. Nada.
FWIW, from my rewrite_log (ditto), re my attempting to visit...
http://www.example.com/directory/file.html
...here's the rewriting (line-broken to fit here):
my.computerIP.here - - [09/Feb/2006:15:39:23 -0800] [www.example.com/sid#8121dd4][rid#812dec4/initial] (1)
[per-dir /path/to/primary/public_html/directory/] redirect to http://www.example.com/index.html [REDIRECT/301]
That's a perfect 301 -- if I'd wanted to go home:)
Man, I love-hate mod_rewrite.
I think there is some server misconfiguration or something that causes this. I've only ever seen a few reports, and basically, it makes no sense.
Jim
Seeing as how most everything else mod_rewrite-related works, and I rely on it very, very heavily, I'm disinclined to awaken the tweaking giant that is my SysAdmin just in case something really important breaks in the process. Like, oh, perl. :)
And you never know, it may turn out to be totally unrelated to some major misconfig. Perhaps my .htaccess file size is getting too big again or someth-- wow. Wow!
(slaps head)
That just dawned on me! 140k seems to be my absolute maximum for all of its contents to work every time, all the time, and mine is 138k as I type. I'll start cutting chunks of my notes-to-self # comments and will post again if doing so does the trick!