Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Probably a simple problem, but I cant seem to figure it out: I've recently created a new website from scratch to replace an older website. The old website had a good SEO ranking which is obviously something I want to keep.

Since the new website also has a new structure there are some directories from the old site/structure which I've dropped completely. However there are quite a lot of external links pointing to these directories, or more specifically files within the old directories. So my questions boils down to this: How do I redirect all/any hits on files within certain sub-directories?

For example: --> --> -->

share|improve this question

Something like this would do the trick:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^/oldsubdirectory/somefile1.file$ [L,R=301]
RewriteRule ^/oldsubdirectory/somefile2.anothertypeoffile$ [L,R=301]

The RewriteCond statement makes these rewrite only apply on the though, so if someone were to access it would NOT be rewritten. You can try both with and without the RewriteCond to see what works best for you.

If you want it to redirect to the same file in newdirectory you have to specify the filename (or match it with regular expression and then recall it later), for example:

RewriteRule ^/oldsubdirectory/(somefile1.file)$$1 [L,R=301]
share|improve this answer
Thank you for your reply. If I've understood you correctly I have to create one rule for every file I had in the old directory? That was sort of what I was hoping to avoid since there are hundres of files in the old directory (Thanks to a shotty CMS). – KG Christensen Jan 8 '12 at 11:09

You can do rewrite rule with rewrite engine as suggested by @Mattias or you can use the more simple form redirect permanent <old url> <new url> Read up at for more information. The information there on this is written in very simple manner. While with redirect permanent there is nothing to learn just use it. There are hundreds of tutorial on url rewrite in apache httpd. Google it

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.