如何重写我的 URL,使其与 $_SERVER[“PATH_INFO”] 配合使用?

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

提问人:Madara's Ghost 提问时间:7/5/2013 更新时间:7/5/2013 访问量:91

问:

我有一个具有单一入口点的应用程序。在该应用程序中,我有以下行:

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

这允许我在访问URL时处理它们,如下所示:

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

一切都很好,但是我是强迫症,我想摆脱URL的一部分。无论我尝试了什么,它都没有按预期工作。index.php

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

等。

其中一些在我的 nginx 错误日志中产生循环错误(重写太多),其中一些根本不起作用。

我在这里停滞不前。我怎样才能成功重写这样的URL?请注意,我使用的是 Nginx 而不是 Apache)。

php url-重写 nginx

评论


答:

1赞 Ignacio Vazquez-Abrams 7/5/2013 #1

消极的展望。

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

评论

0赞 Madara's Ghost 7/5/2013
谢谢你的回答。我会试一试,然后回复你。