Well, let's seePeter said:I have a hard time debugging rewrite rules in my head so I assume the above codes are correct.
Indeed Peter. The OP isn't very helpful in anyway. The only use case for it is (as far as I can see) when one is hosting one domain on his server and wants for some odd reasons to redirect all the incoming requests (which are assumed to be targeting it) to somewhere else. Doesn't make much practical sense.Peter said:The first one, posted by melchor, will redirect all requests so it should only be used if the new domain is stored elsewhere. If both domains point to the same location on the server this code would create an infinite redirection loop.
It's the sensible way of doing what the OP was thinking has solved. In other words, it checks for the domain part of requests instead of blindly/systematically performing redirects. A more contracted version would be:Peter said:The second one, posted by vanek988, works the same except that it only redirects if the domain name is correct. This can be used to redirect an old domain to a new domain, or the www version of the domain to the non-www version (or vice versa).
<ifModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301]
</ifModule>