Webmasters Stack Exchange is a question and answer site for pro webmasters. 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

I have a bunch of old files prefixed with "old-" (e.g. "old-abcde.php"). I need an htaccess rule to set up a 301 redirect so that any request for a file starting with "old-" goes to its corresponding new version (e.g. "abcde.php").

To be clear, I have many files, not just one, so I can't do a literal filename match. I basically just need to strip off the "old-" from request and redirect to the version without it.

I know I probably just need a simple regular expression, but I'm not good at writing them. Can anyone provide assistance?

share|improve this question

Try ModRewrite:

RewriteEngine On
RewriteRule old-(.*)$ $1 [NE,R]

This sends an 301 to the browser and redirects it.

share|improve this answer

I would use this in the .htaccess file :

RewriteEngine on
RewriteRule old-(.*)$ $1 [L,R=301]

Add QSA between the brackets if you have to keep the additional query string (like ?ID=xxxxx). Specify R=301 to make a 301 redirect and specify the redirect is permanent.

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.