【发布时间】:2011-07-26 11:18:10
【问题描述】:
我在 nginx 或 Apache 中重写了这个地址:
http://domain.com/hello
到像这样的脚本
http://domain.com/test.php&ref=hell
如何在 PHP 中访问这个重写的 URL?因为,如果我使用$_SERVER['REQUEST_URI'],我当然会得到:
/test.php&ref=hell
但我只想:
/hello
这可能吗?感谢您的帮助。
更新 nginx cnf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server
{
listen 80;
server_name domain.test;
location /
{
rewrite ^/(main|best|air)$ /core/feeds.php?act=$1 last;
proxy_pass http://127.0.0.1:8080;
}
}
【问题讨论】:
-
你能发布你的重写代码吗?在 apache 中,REQUEST_URI 应该返回用户用来访问页面的 URI。这是我在使用 modrewrite 时得到的行为。我不禁认为你做的是重定向而不是 modrewrite