The easiest way to redirect all traffic from an old site to a new site is to use mod_rewrite with Apache in your .htaccess file. If this file does not already exist in the root of your site’s public folder, then go ahead and create it with a text editor. I suggest using vim.
Then pop this into it:
RewriteEngine On
RewriteRule (.*) http://new.example.com/$1 [L]
The above recipe has the added benefit of also appending the page the user was requesting to the end, so if the new site is a clone of the old site then this will ensure that your users get the page that they requested. There are easier ways to do this if you are just changing URLs out and the site will be on the same server, but this is the easiest way to redirect all traffic if the new site is on a different box all together.
This is the professional blog of Eric Marden, a veteran web developer, entrepreneur, and inspirational speaker.
If you're new here, please subscribe to my RSS feed. You'll get a blend of tech news, analysis, inspirational essays, and much more. Subscribe today.
comments