How to hide the PHP extension in nginx

Home > Search > How-to
  by

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.

 

Ensure your /etc/nginx/nginx.conf file has the following.

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

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include fastcgi_params;
}

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

 

 

Now, .php will no longer be displayed.

 



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 in the box below so that we can be sure you are a human.




Comments