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.

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
add comment

2 Answers

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
add comment
 location /about/ {
  proxy_pass http://backend/about.php;
 }

or

# 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
add comment

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.