Adding automatic extension (php) on nginx

Adding automatic extension (php) on nginx

Date Posted:25-05-2017

Well, normally no one likes to expose the language written on their website. On apache, we will use .htaccess to autoadd the extension. In this post, we will show on how to autoadd the extension on nginx configuration.

Incase, if nginx is not installed by default follow the below post to install nginx on the server.

Implementation:

Open the nginx configuration and add the below lines to autoadd extension.  Incase, if we want to particular domain, we need to update corresponding domain configuration.

vi /etc/nginx/sites-enabled/default

location / {
try_files $uri $uri.html $uri/ @extensionless-php;
index index.html index.htm index.php;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}

Check the nginx syntax error.

nginx -t

Restart the nginx service for the changes come into effect.

systemctl restart nginx

 

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Reply

Scroll to Top