We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on Vesta 2.0 and expect to release it by the end of 2024. Read more about it: https://vestacp.com/docs/vesta-2-development
Remove .PHP extension in NGINX?
Remove .PHP extension in NGINX?
How can i remove the .php extensions from my urls?
For example:
www.domain.com/page.php
to
www.domain.com/page
I have searched for a solution alot but couldn't find one for vestacp :(
For example:
www.domain.com/page.php
to
www.domain.com/page
I have searched for a solution alot but couldn't find one for vestacp :(
-
- Support team
- Posts: 1096
- Joined: Sat Sep 06, 2014 9:58 pm
- Contact:
- Os: Debian 8x
- Web: apache + nginx
Re: Remove .PHP extension in NGINX?
That's a mod_rewrite feature, nothing exactly to do with VestaCP. You can do this by editing your .htaccess
Very detailed instructions and discussion here, you must read and test the different settings discussed.
Remove .php extension with .htaccess
Code: Select all
RewriteEngine on
RewriteRule ^(.*)$ $1.php
Remove .php extension with .htaccess
Re: Remove .PHP extension in NGINX?
What Megargags has suggested would work, but only on Apache based servers.
For nginx you would need something similar to the following,
For nginx you would need something similar to the following,
Code: Select all
location / {
try_files $uri $uri.html $uri/ @extensionless-php;
index index.html index.htm index.php;
}
location ~ \.php$ {
try_files $uri =404;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
Re: Remove .PHP extension in NGINX?
Thanks for the replies.Phogo wrote:What Megargags has suggested would work, but only on Apache based servers.
For nginx you would need something similar to the following,
Code: Select all
location / { try_files $uri $uri.html $uri/ @extensionless-php; index index.html index.htm index.php; } location ~ \.php$ { try_files $uri =404; } location @extensionless-php { rewrite ^(.*)$ $1.php last; }
Im using NGINX - PHP-FPM, therefore the .htaccess method will not work for me.
When i use your code above (googled it and tried it before, tried it again now)
I get the following error:
Code: Select all
root@ub3r:~# nginx -t
nginx: [emerg] named location "@extensionless-php" can be on the server level only in /home/trash/conf/web/nginx.conf:21
nginx: configuration file /etc/nginx/nginx.conf test failed
But now wen i access any page, the page automaticly gets downloaded instead of showign normally o.0
Re: Remove .PHP extension in NGINX?
Do you have duplicate
Code: Select all
location / {
try_files $uri $uri.html $uri/ @extensionless-php;
index index.html index.htm index.php;
Re: Remove .PHP extension in NGINX?
No, i took care of this part too.Phogo wrote:Do you have duplicateCode: Select all
location / { try_files $uri $uri.html $uri/ @extensionless-php; index index.html index.htm index.php;
nevermind, i tried it again and now it worked o.0
do you have a idea, how i can automaticly remove the .php aswell as index?
Thanks alot for the support