【问题标题】:How to rewrite my URL so that it works well with $_SERVER["PATH_INFO"]?如何重写我的 URL 使其与 $_SERVER["PATH_INFO"] 一起工作?
【发布时间】:2013-07-05 15:27:53
【问题描述】:

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

$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-rewriting nginx


    【解决方案1】:

    负前瞻。

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

    【讨论】:

    • 感谢您的回答。我会试一试,然后回复你。
    猜你喜欢
    • 2011-10-23
    • 1970-01-01
    • 2016-12-31
    • 2019-11-13
    • 2012-10-16
    • 1970-01-01
    • 2023-04-10
    • 2012-01-06
    • 2023-03-05
    相关资源
    最近更新 更多