1

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.

1

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.

| improve this answer | |
0
 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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.