Welcome! Log In Create A New Profile

Advanced

Hide extension and take PATH_INFO ?

Posted by nginabanks 
Hide extension and take PATH_INFO ?
May 13, 2016 07:42PM
With Apache, this address:

http://www.example.com/abc/def/ghi/jkl/mno

will work if any of these files exist:

/abc.php
/abc/def.php
/abc/def/ghi.php
/abc/def/ghi/jkl.php
/abc/def/ghi/jkl/mno.php

without even turning on mod_rewrite. It takes just these two lines:

Options MultiViews
AcceptPathInfo On

(Actually, for .php files and other scripts, you don't even need AcceptPathInfo. It's on by default). The remaining extra path will become $_SERVER['PATH_INFO'].

I can't figure out how to do it in nginx. It seems to handle only simple rewrites.

But this is very useful for a busy team that handles a few dozen applications on a corporate intranet. We can drop dynamic pages in among various static files, without having to add Location blocks to the central config files and restart the web server.



Edited 2 time(s). Last edit at 05/13/2016 07:44PM by nginabanks.
Re: Hide extension and take PATH_INFO ?
May 14, 2016 02:49AM
location ~ \.php$ {
........

http://stackoverflow.com/questions/2237189/serving-php-files-from-different-locations-in-nginx

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Hide extension and take PATH_INFO ?
May 14, 2016 12:02PM
If I put a .php file at http://www.example.com/a.php, then I want it to run if the user goes to http://www.examle.com/a, http://www.example.com/a/b, or http://www.example.com/a/b/c.
Re: Hide extension and take PATH_INFO ?
May 14, 2016 12:13PM
location ~ \.php$ {
.......
index a.php b.php;

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Hide extension and take PATH_INFO ?
May 14, 2016 12:47PM
> location ~ \.php$ {

".php" won't be in the web address, so this won't work.

> index a.php b.php

I'm not sure how this would help either. I don't want to list the .php files one by one in the server configuration. I want to be able to add files at will to my website, without having to edit the nginx config for each path.

I want to be able to add, for example, /rhubarb.php, and it instantly be reachable at /rhubarb. I also want anything you type after /rhubarb to match /rhubarb.php. So if the user went to /rhubarb/1234, or /rhubarb/something, or /rhubarb/something/something, they would all run /rhubarb.php.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 206
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