Redirect http requests to a new folder with apache rewrite rules

Friday, August 12, 2011 posted by Till

When you reorganize the structure of a website, you might want to redirect requests to files in a old folder to a new one without loosing the pagerank. In this example, I will redirect all requests from directory "olddir" to directory "newdir", so that requests like http://www.yourdomain.tld/olddir/page.htm get redirected to http://www.yourdomain.tld/newdir/page.htm without loosing the Google pagerank of the pages.

The following rewrite rules can be added into a .htaccess file in the website directory or in the vhost configuration.

RewriteEngine on
RewriteRule ^olddir/(.*)$ newdir/$1 [R=301,L]

This rewrite rule redirects automatically all requests to pages or subdirectorys of "olddir" to the same page or subdirectory in "newdir".

Be Sociable, Share!



One Response to “Redirect http requests to a new folder with apache rewrite rules”

  1. Awesome blog and post! Cheers! How long has this blog been running now? The only thing is I seem to be having slight technical difficulties getting to your RSS feed though.

Leave a Reply