0

Our company website used to run on PHP but has now been moved over to Ruby On Rails and no longer contains any .php file extensions in the url. We wan't to try and handle all the legacy url requests still containing the .php extension and simply redirect them to the requested page without the extension. Is this possible in NGINX?

Previously I was doing something to the effect of:

location /somesubdirectory/somepage.php {
  return 301 http://example.com/somesubdirectory/somepage;
}

However, for reasons beyond me the above code only seems to handle the redirect sometimes. After an unknown period of time it just up and breaks, and then at random works like magic again - likely a separate configuration issue on my end. Additionally, even if the above worked as anticipated, it would quickly become cumbersome to define one of these for the 50+ pages on my website so I'm really looking for a more elegant solution than this.

1 Answer 1

1

This location block should redirect all php requests.

location ~ \.php$ {
    rewrite ^(.*)\.php$ http://example.com$1 permanent;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.