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".

Redirect http requests to a new folder with apache rewrite rules
Facebooktwittergoogle_plusredditlinkedinmail
Tagged on:         

One thought on “Redirect http requests to a new folder with apache rewrite rules

  • May 5, 2012 at 12:46 pm
    Permalink

    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.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *