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.

2 Answers 2

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .