Madara's Ghost
Madara's Ghost

Reputation: 174957

How to rewrite my URL so that it works well with $_SERVER["PATH_INFO"]?

I have an application with a single point of entry. In that application, I have the following line:

$url = !empty($_SERVER["PATH_INFO"]) ? $_SERVER["PATH_INFO"] : "/";

This allows me to process URLs when I access them like so:

http://localhost/index.php/controller/action?get=variables

All is well, but the OCD I am, I want to get rid of the index.php part of the URL. And no matter what I've tried, it didn't work as expected.

RewriteRule ^(.+)$ /index.php/$1 [L]
#or
RewriteRule ^([^.]+)$ /index.php/$1 [L]

etc.

Some of them produce a loop error in my nginx error log (too many rewrites), some of them just don't work at all.

I'm at a standstill here. How can I successfully rewrite such a URL? Note that I'm using Nginx and not Apache).

Upvotes: 1

Views: 92

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798536

Negative lookahead.

RewriteRule ^(?!index\.php)(.*)$ /index.php/$1 [L]

Upvotes: 1

Related Questions