Here’s a good rule set for forcing use of a preferred url:
1 2 3 |
RewriteCond %{HTTP_HOST} !^desired\.domain\.name(:.*)?$ [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/?(.*) http://desired.domain.name/$1 [L,R=301] |
This version of the canonical rewrite expands on the original found here:
http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html#canonicalhost
by adding:
- redirects domains with suffixes (not just prefixes) back to the canonical host; and
- allows Host request headers to contain port specifiers (which is allowed by RFC2616 section 14.24)
as suggested here:
http://colby.id.au/node/99
and by using a 301 redirect as recommended by Google here:
http://www.google.com/support/webmasters/bin/answer.py?answer=44231&hl=en