Redirecting From One Domain To Another Using Mod Rewrite

Use the following rules in your Apache configuration (or your .htaccess file) to redirect all traffic from one domain to another. This also keeps the query string in place so that the user isn't just dumped to the homepage.

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

These rules are mod_rewrite dependent, so you'll need that module enabled in your Apache install.

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
7 + 8 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.