Forum Moderators: phranque
I thought this might do it, but it doesn't:
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com
RewriteRule ^/(.+) [mysite.org...] [R,L]
What am I doing wrong?
Welcome to WebmasterWorld [webmasterworld.com]!
That code should work (almost right) *if* you put it in httpd.conf. For use in .htaccess, try:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule ^(.*) http://www.example.org/$1 [R=301,L]
If you want to redirect *ALL* hostnames that are *not* exactly equal to "www.example.org", try this variant:
RewriteCond %{HTTP_HOST} !^www\.example\.org
RewriteRule ^(.*) http://www.example.org/$1 [R=301,L]
This will "correct" any URL that is not exactly an all-lowercase www.example.org. This construct can be used to simplify all the other RewriteRules and other hostname tests in scripts, etc., by ensuring that only one version of your hostname will be used to access your site.
Ref: Introduction to mod_rewrite [webmasterworld.com]
Jim