Search engine friendly page redirects using Apache mod_rewrite

When redirecting a visitor from one page or address page on your site to another, it is important to also bear in mind the effect this will have with search engines. Not all redirect methods are search engine-friendly, so to make sure that the search engines find the new page, and that any “link juice” from the old page is carried on to the new one, make your redirects SEO friendly.

As a general rule of thumb, the redirect should take place server-side, rather than client side. While client-side methods exist, such as meta-refreshes or Javascript redirecting, search engines often ignore these and will continue to cache the old page, rather than the new one. While visitors will see the new page, search engines might not.

A server-side redirect means that the new page is fetched on the server and sent directly to the client (in this case the search engine bot) in place of the old page – the search engine doesn’t get to see the old page anymore, even if visiting the old page’s URL.

On a Linux server, this can be accomplished using the .htaccess file in your public_html (root) folder on your account. Login to your FTP account, and navigate to the public_html folder. Then edit the .htaccess file, and paste in the following code:

RewriteEngine On
RewriteRule    ^old_page.html$    new_page.html    [R=301,NC,L]

The first part, RewriteEngine On, simply tells your server to use the mod_rewrite module on your web site. You should put this at the top of the .htaccess file. If it has already been declared, there is no need to put it in a second time though.

The second part of the code actually performs the action. Replace old_page.html with the location of your old page, and new_page.html with the desired new location. It is not necessary to add your web site’s URL (http://www.yourdomain.com) to this – simply add where your file is located, relative to the public_html folder.

Leave a Reply