Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- Rewrite rule troubles


jdMorgan - 6:07 am on Jul 30, 2008 (gmt 0)


Obviously the "RewriteCond %{HTTP_HOST} . " line was not needed.

If your site is accessible via HTTP/1.0, and you get an HTTP/1.0 request, then your server will go into an infinite loop without that line.

Your code was looping because bad_domain.html matches your ".*" RewriteRule pattern, and so can be externally redirected or internally rewritten to itself. That, combined with a configuration setting of UseCanonicalName on with a ServerName defined as anything other than exactly "www.mydomain.com" would set up a loop. You can use a server headers checker to test your original code to see if this was likely the case. If so, ask your host to turn off UseCanonicalName (See Apache core for more info).

Aside from that, you could save some code space and CPU time with your most-recently-posted version:

RewriteCond %{HTTP_USER_AGENT} googlebot¦Msnbot¦Slurp [NC]
RewriteCond %{HTTP_USER_AGENT} !AdsBot-Google [NC]
RewriteCond %{HTTP_HOST} !^(www\.)?mydomain\.com [NC]
RewriteCond %{HTTP_HOST} !^(www\.)?mydm\.com [NC]
RewriteRule !bad_domain\.html$ bad_domain.html [L]

This eliminates two redundant RewriteConds by making the remaining patterns match your hostnames with or without the leading "www.", and prevents the potential looping problem.

Backing up to take an overview here, I'm wondering why you'd want to create massive duplicate-content on your non-canonical domains, since all requests for *any* URL in those domains will now return the same "bad_domain.html" page; This creates infinite URL-spaces on those domains, and massive duplicate content.

Why not just 301-redirect requests for any of your non-canonical hostnames to the correct page(s) on your main domain instead?

Jim


Thread source:: http://www.webmasterworld.com/apache/3710219.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com