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

Looking to make rewrite my urls so pages don't end in /.php.

For example, I want to make '/about.php' look like '/about' or '/about/'

Can anyone share the module to do this? If you have an nginx.conf or virtual.conf file example that shows this type of rewrite I would be grateful.

Obviously, I am a noob but trying to learn by example.

share|improve this question

You can use the try_files directive to check for a file with .php appended. For example:

try_files $uri.php $uri;

This will first look for /about.php and then process /about if it doesn't exist.

share|improve this answer
 location /about/ {
  proxy_pass http://backend/about.php;


# this will catch ALL files and rewrite ALL requests
 (like /blabla/file to /blabla/file.php)
# it is not tested , but I guess you will understand this :)

location / {
    rewrite ^/(.+)$ /$1.php break;
    proxy_pass http://backend;

or may be simplest way

location / {
    proxy_path http://backend$uri.php #append .php to all files

end remember that rewrite module is slow.. try to avoid 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.