Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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;
}

domain.com/folder/filename.asp 301 redirect to domain.com/folder/filename.php

Thanks

share|improve this question

1 Answer 1

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$ http://example.com/$1.php permanent;
share|improve this answer
    
Thanks. That worked like a charm ! –  webnise Oct 21 '12 at 0:45

Your Answer

 
discard

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.