Web redirects
Wednesday, September 24th, 2008A few weeks ago, at work, we decommissioned a few websites, and the business wanted traffic from the old websites to redirect to a specific page on our main website. That’s a pretty simple task, and there’s a number of ways to complish it: use a CGI script, “Refresh” directive in the webpage, mod_alias, mod_rewrite, or .htaccess.
We decided on using mod_alias since at first glance that was the easiest. It works fine as long as you are trying to go to the root document of the website, i.e. trying to go to www.website.com will get redirected to www.newwebsite.com. But the problem arose that www.website.com/some/path/here.html would end up redirecting to www.newwebsite.com/some/path/here.html and of course that page didn’t exist on the new website. This was a major issue for the business because they were concerned about bookmarked links to sub-pages, or links in old email fliers.
In order to work around this we had to go with mod_rewrite to redirect any and all request to the old website and forward them on to the appropriate page on the new website. We setup a vhost on one of our apache servers for the old website and added the following:
RewriteEngine On
RewriteRule /.* http://new_url [R=301]
Here’s what our vhost entry looked like:
<VirtualHost XXX.XXX.XXX.XXX>
ServerName oldwebsite.com
ServerAlias www.oldwebsite.com
RewriteEngine On
RewriteRule /.* http://new_url [R=301]
</VirtualHost>
It was that simple, too bad we didn’t think of that from the start.

