Forum Moderators: phranque
__________________________________________________________
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.example.com/ [R=301,L]
ErrorDocument 404 /error.html
__________________________________________________________
So i'm stumped, i'm not sure if it could possibly have something to do with me changing my dreamhost setting from
Add "www." if somebody goes to [domain.com...]
to
Both [domain.com...] and [domain.com...] work.
( but if i'm using my htaccess file to redirect this it shouldn't matter )
well hopefully im just overlooking something simple and someone can help me out
Your index redirect only works for index files in the root. See this thread for more complete code: [webmasterworld.com...] that works both in the root and in folders.
All redirects should correct the domain name within their own redirect. This helps to prevent chains of redirects.
The thing that isn't making sense is when i go to example.com it'll redirect to http://www.example.com in my browser but for some reason it's still listing both of the URL's as seperate sites?
Rreverse DNS is something different. If you have two domain names hosted at that IP then two domain names will be listed - because those *names* do exist.
However, once someone visits the non-www URL, your redirect will correct the URL that they 'see' and 'use' on the web.
The fixes I mentioned above are 100% necessary for HTTP accesses, but have no bearing on anything at the DNS level.
The DNS system is not influenced by .htaccess at all --DNS servers and your Web server are not even on the same computer(s)-- and in fact, if you were to look up my sites, you might find that they have an "infinite" number of hostnames on one IP, because I have configured wild-card DNS, which allows any and all subdomains -- "www", "test", "mobi", or any other subdomain you'd care try will in fact resolve to my server. However, aside from the short list specified here, all other subdomains are redirected to one of those listed as the canonical domain.
So, I think you're simply seeing a badly-worded report or mis-interpreting what you see. As long as any non-www request gets redirected to the www subdomain in one single 301 redirect you will be fine. I suggest testing with the Live HTTP Headers add-on for Firefox/Mozilla browsers to verify this.
Options +FollowSymLinks -Indexes
RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.example.com/$1 [R=301,L]
#
# Expanded "www" and "non-www" hostname canonicalization rule
RewriteCond %{HTTP_HOST} ^example.\com [OR]
RewriteCond %{HTTP_HOST} ^www\.example.\com. [OR]
RewriteCond %{HTTP_HOST} ^www\.example.\com:[0-9]+
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
# Alternate "catch-all" hostname canonicalization rule
RewriteCond %{HTTP_HOST} !^www\.example.\com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
I'm definitely not an apache expert so you lost me with the code jdmorgan haha but i'll make the changes g1smd first stated.
Unless i need to use that full code you used JD? I'm really not quite sure what some of it is doing but if it's needed i'll use it
You need block 1 and 2 OR you need block 1 and 3.
Note that blocks 2 and 3 are two different ways of coding the same thing; pick one of them.
Additionally, see that each block of code is commented and blocks are separated with a blank line. This makes it easy to look at the code when you come back to it in months or years in the future.
Don't forget to comment and add back on your ErrorDocument line again.