Forum Moderators: phranque

Message Too Old, No Replies

Redirect Googlebot to 80 with .htaccess

Google has been indexing our URLs through port 443...

         

mycrazydream

5:22 pm on Dec 30, 2008 (gmt 0)

10+ Year Member



I wanted to verify that this would work to redirect only googlebot to port 80 before I test it out on our server. We've recently updated our entire database and I can't take the chance of making googlebot unhappy, but I would like to get this working.


RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_USER_AGENT} ^Googlebot.*
RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R,L]

jdMorgan

5:35 pm on Dec 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Strongly recommend that you specify [R=301,L] so that a 301-Moved Permanently status is returned...

Also, check the user-agent string pattern. It will not match googlebot's current UA, because it starts with "Mozilla/5.0 (compatible; Googlebot/" and not with "Googlebot".

Jim

mycrazydream

7:06 pm on Dec 30, 2008 (gmt 0)

10+ Year Member



This should handle it then, yes?


RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_USER_AGENT} .*Googlebot.*
RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

mycrazydream

7:43 pm on Dec 30, 2008 (gmt 0)

10+ Year Member



This worked perfectly - I was able to test by spoofing the User-Agent string in Firefox. One last note - I use redirects in order to create more human readable URL's. Make sure that the bot redirect is above that those in your htaccess and also has the L so that no other redirects are processed.

jdMorgan

8:57 pm on Dec 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No need to prepend or append ".*" to the pattern -- it's a waste of CPU time, and an unanchored pattern will behave the same with or without that.

Now you should look into the canonicalization issues that got you into this in the first place; Any requests for the non-canonical domain should 301-redirect to the canonical domain, and any requests for pages or sections of your site that are made using the wrong protocol by *any* client should be redirected to force use of the correct protocol. You will find these subjects already fairly well-covered here if you want to try a few searches.

Jim