How to properly 301 Redirect URL’s with Apache, IIS, PHP, ASP and ColdFusion
Properly translating your search-unfriendly URL’s into search-lovable ones, or just scrambling up your information architecture (or “IA”, which is essentially a site’s navigational structure, with respect to the way content is organized) into something more delicious to bots and humans alike should be a straightforward process. Many of us had to learn this process from trial-and-error (trial by fire more like it) or, if you were lucky, from popular SEO folklore.
Unfortunately the real-world examples provided with Apache’s mod_rewrite instructions are somewhat outdated and irrelevant, and totally lack any description of how to perform a proper 301 redirect or why it’s important to do so.
That is, if your web server even has Apache mod_rewrite installed, which some hosts don’t and won’t, so if you have one of those hosts my best advice is to run far, far away. Oh, and make sure your new host doesn’t also delete your log files after 5 days, which a surprising number of bad web hosting services do. Imagine if a stock broker permanently deleted all stock performance data after a week and never looked back! What NERVE!
If you’re hosting on IIS and have have administrative access to the server, do not despair that Redmond has let you down once again, for third-party developers have come yet again to save the day for anyone foolhardy enough to run a server off such a toy operating system. You can install either ISAPI Rewrite or IISRewrite to mimick the behavior of Apache mod_rewrite on a Windows IIS server. This is a great option if legacy code, butt-headed bosses or just plain lack of qualified human resources preclude a platform switch to a real server OS such as BSD or Linux.
If your host won’t offer mod_rewrite or one of those IIS plugins, and moving hosts is not an option, or for a quick-fix Macgyver solution, you can perform 301 redirects by sending the appropriate HTTP headers using your server-parsed scripting language of choice, such as PHP, ASP, ASP.NET or ColdFusion. It looks the same to search bots, but may be a bit slower than a solution that operates from within the web server software itself.
It is with all these inherent difficulties in mind that I wrote this comprehensive 301 redirect howto page to try to shed some light on this poorly-understood and tremendously-important methodology of protecting your search traffic from your changing IA and enticing the bots to crawl friendlier URL’s. It includes instructions for Apache .htaccess (mod_rewrite), IIS (w/admin access), PHP, ASP and ColdFusion.