Forum Moderators: phranque

Message Too Old, No Replies

Changed My .htaccess file. now i'm getting two different homepages

Changed My .htaccess file and now when i do a reverse ip search i have two

         

gbgamblers23

2:06 pm on Mar 20, 2009 (gmt 0)

10+ Year Member



Well I changed my .htaccess file and now when i do a reverse ip search i have two homepages. One at example.com and www.example.com? I swear my .htaccess file should be solving this but for some reason it isn't. This is the code i'm using :

__________________________________________________________

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

gbgamblers23

2:10 pm on Mar 20, 2009 (gmt 0)

10+ Year Member



added info

with my htaccess file all im trying to do is remove the index.html from www.example.com/index.html and add a "www." to my site if someone visits example.com (for duplicate canonical issues)

i think this is a pretty standard thing to implement and for some reason it's just not working

g1smd

2:10 pm on Mar 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You need to list the index redirect before the non-www redirect. As you have it now a non-www index request is passed through a 'chain' of two redirects to reach the final URL.

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.

gbgamblers23

2:15 pm on Mar 20, 2009 (gmt 0)

10+ Year Member



thanks for the advice g1smd i just implemented that but i'm still getting two different homepages when i do the reverse ip.

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?

g1smd

2:21 pm on Mar 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The HTaccess solves duplicate issues for HTTP accesses to your site.

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.

jdMorgan

2:35 pm on Mar 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Other than the rule order noted above, and missing escapes on literal periods within regex patterns, I doubt that you have a problem.

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]

Jim

g1smd

2:44 pm on Mar 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That'll do the job! Good stuff.

gbgamblers23

3:03 pm on Mar 20, 2009 (gmt 0)

10+ Year Member



Thanks guy, i think you both nailed it. I was basically thinking of the DNS and webserver as the same thing.

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

g1smd

3:05 pm on Mar 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes. jd has implemented the code that I was suggesting, with a couple of extra useful fixes that I didn't mention.

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.

gbgamblers23

5:03 pm on Mar 20, 2009 (gmt 0)

10+ Year Member



thanks i'm gonna set this up right now

thanks again for all your help g1smd and jdMorgan

gbgamblers23

5:11 pm on Mar 20, 2009 (gmt 0)

10+ Year Member



hey guys the htaccess code doesn't redirect from example.com to www.example.com

i'm not quite sure what a few of the things in the code mean so i really have no idea how to fix it haha

g1smd

5:39 pm on Mar 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As coded in the above example, I see no errors or typos.

gbgamblers23

6:51 pm on Mar 20, 2009 (gmt 0)

10+ Year Member



alright i think the problem might have something to do with the server thanks for replying