Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 changed my file names from filename.asp to filename.php but now I want to 301 redirect all the requests coming to filename.asp to its equivalent filename.php

I have tried these variations but they only redirect to the homepage:

if ($request_uri ~ .*.asp.*) {

     rewrite ^ http://$host? permanent; 
     #rewrite ^/(.*)$ /$1.php permanent;
} 301 redirect to


share|improve this question
up vote 0 down vote accepted

You don't need the if to get just the .asp files, it can be handled purely in the rewrite:

rewrite ^/(.*)\.asp$$1.php permanent;
share|improve this answer
Thanks. That worked like a charm ! – webnise Oct 21 '12 at 0:45

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.