Forum Moderators: phranque

Message Too Old, No Replies

Deny access to requesting the site by 100.100.100.100

but allow www.example.com

         

astro_miner

2:45 pm on Nov 3, 2005 (gmt 0)

10+ Year Member



Is there a way to do this? I have dedicated IP's on my sites and want to avoid the duplicate penalty in google.

Or does google care at all?

I feel a little 302 vulnerable right now. :(

jdMorgan

3:46 pm on Nov 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, use mod_rewrite, and test %{HTTP_HOST} for an IP address rather than a hostname. If it's an IP address, then 301-redirect to the hostname.

You might want to add an exclusion to it, so that you can access the site by IP address from your own IP address by testing the %{REMOTE_ADDR} variable. This can be helpful if you suffer a DNS failure and need to view your site while the DNS-based world thinks it's off-line.

It's a good practice to redirect all domain aliases --including the IP address-- to the canonical domain right from the first day a site exists. This prevents all the endless canonicalization problems we see in the major SE forums right from the start.

Per our forum charter, take a shot at the code and we'll help you get it working.

Jim

astro_miner

5:40 pm on Nov 3, 2005 (gmt 0)

10+ Year Member



RewriteCond %{HTTP_HOST}!^.*example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Voila.

jdMorgan

6:34 pm on Nov 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



... or the standard version that redirects all "alias" domains and IP accesses:

RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Jim