Welcome! Log In Create A New Profile

Advanced

Hide .php extension in URLs

Posted by neek 
Hide .php extension in URLs
September 13, 2015 11:36AM
Hi, I'm struggling with getting rewrites to work so that I can hide the ".php" on file extension. I'm running a photo site (called Piwigo) on nginx, and it creates URLs of the form:

http://example.com/SOMESCRIPT/param1/param2/param3#whatever

In this case, SOMESCRIPT is actually a file on disk called "SOMESCRIPT.php". I'm trying to configure rewrites so that (1) first try to see if the URL is a path on disk; (2) if not, try to send it on to the PHP script by adding a ".php" after the first word in the URI.

Here's the relevant section that I've tried. Any help is most welcome.

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

location @rewrite {
rewrite ^/picture((/|$).*)$ /picture.php$1 last;
rewrite ^/index((/|$).*)$ /index.php$1 last;
rewrite ^/i/(.*)$ /i.php/$1 last;
rewrite ^/../../../i/(.*)$ ../../../i.php/$1 last;
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 177
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready