Join the community today
Register Now

Nginx Removing .php and .html/.htm extensions?

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by tdubs, Jun 21, 2015.

  1. tdubs

    tdubs Member

    77
    11
    8
    Apr 10, 2015
    Ratings:
    +14
    Local Time:
    5:21 PM
    1.7.12
    10.0.17
    Hello,

    So I am wanting to clean up my URLs to my forum by removing the .php and .html/.htm extensions. I checked out Stack Overflow and found the best way to do so for an Nginx setup is to append the following /usr/local/nginx/conf/conf.d/mydomain.com.conf and include:

    Code:
    server {
    index index.html index.php;
    location /{
    try_files $uri $uri/ $uri.html $uri.php?$query_string;}
    location ~ \.php$ {
    try_files $uri =404;# add fastcgi_pass line here, depending if you use socket or port}}
    
    However, I know the config file is setup differently to an extent and I don't want to mess anything up. How can I go about properly doing this?

    Thanks! :)
     
  2. eva2000

    eva2000 Administrator Staff Member

    29,033
    6,589
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,782
    Local Time:
    5:21 PM
    Nginx 1.13.x
    MariaDB 5.5