Forum Moderators: phranque

Message Too Old, No Replies

Need help with .htaccess

         

ispgeek

3:58 am on Feb 15, 2011 (gmt 0)

10+ Year Member



Howdy,

To combat a recent problem with google crawling our server IP vss domain name we added some additional code to our .htaccess file.

Now I have it working for the most part with the following code with one exception it redirects the originating url to our main page (which compared to what it was doing previously is still much better) but...

Now here is an example of one the urls that google managed to crawl:

http://174.34.146.18/~ispgeeks/wild/modules.php?name=Voip_Firewall


With the code added below:

RewriteCond %{HTTP_HOST} ^174\.34\.146\.18
RewriteRule (.*) http://www.ispgeeks.com [R=301,L]


It redirects nicely to :
http://www.ispgeeks.com


Wanting it to correctly redirect to the actual page intended I changed the code as follows:

RewriteCond %{HTTP_HOST} ^174\.34\.146\.18
RewriteRule (.*) http://www.ispgeeks.com%{REQUEST_URI} [R=301,L]


Which in fact does redirect to the correct page except the link except for one minor (well major but it still works) problem:

http://www.ispgeeks.com/~ispgeeks/wild/modules.php?name=Voip_Firewall


Notice the "/~ispgeeks" ?(minus the quotes)

This is what I need to remove or prevent from being passed to the corrected url. I've pretty much tried everything I can think of so I'm open to new ideas and would really appreciate your help.

Thanks!

ispgeek

11:33 pm on Feb 15, 2011 (gmt 0)

10+ Year Member



Any gurus out there wanna take a stab at this? Could really use some advice :)

jdMorgan

12:59 am on Feb 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Correcting your original code:

RewriteCond %{HTTP_HOST} ^174\.34\.146\.18\.?(:[0-9]+)$
RewriteRule ^(.*)$ http://www.ispgeeks.com/$1 [R=301,L]

If this rule gives the same problem (including the mod_userdir path), then

RewriteCond %{HTTP_HOST} ^174\.34\.146\.18\.?(:[0-9]+)$
RewriteRule ^(~ispgeeks/)?(.*)$ http://www.ispgeeks.com/$2 [R=301,L]

will take care of that.

Consider combining this with your existing hostname canonicalization rule, or expanding it to include that function if you don't already have a hostname canonicalization rule. This will redirect any request for any hostname except exactly www.ispgeeks.com to www.ispgeeks.com, retaining the requested URL-path, including appended FQDN tokens and/or port numbers, as well as casing errors:

# Externally redirect all non-blank non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.ispgeeks\.com)?$
RewriteRule ^(.*)$ http://www.ispgeeks.com/$1 [R=301,L]

Tweak as per the second rule if needed.

Jim