Nginx (Web Server) - hide .php extension

By default, the .php extension will show in a web browsers address bar. For example, if you've a page named About.php, the address bar will show www.example.com/About.php.

 

Update the try_files directive in your main location block in your nginx.conf file to have @extensionless-php.

location / {
    try_files $uri $uri/ @extensionless-php;
}

 

Also add an @extensionless-php location block and restart nginx for this change to take effect.

location @extensionless-php {
    rewrite ^(.*)$ $1.php last;
}

 

Now, .php will no longer be displayed.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 66465 in the box below so that we can be sure you are a human.




Comments


September 28th, 2022 by freqnoiz
Did just that and the browser started to download all php files :D GREAT

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |