本文介绍了Apache 重写 - 在 PHP 中获取原始 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 nginx 或 Apache 中重写了这个地址:
I have a rewrite in nginx or Apache for this address:
domain/hello像这样的脚本
domain/test.php&ref=hell如何在 PHP 中访问这个重写的 URL?因为,如果我使用 $_SERVER['REQUEST_URI'] 我当然会得到:
How can I access this rewritten URL in PHP? Because, if I use $_SERVER['REQUEST_URI'] of course I get:
/test.php&ref=hell但我只想:
/hello这可能吗?感谢您的帮助.
Is this possible? Thanx for help.
更新 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 127.0.0.1:8080; } } 推荐答案在Nginx conf中,我们需要添加带有request_uri的用户头:
In Nginx conf, we need to add user header with request_uri:
proxy_set_header request_uri $request_uri;并在php中阅读:
echo $_SERVER['HTTP_REQUEST_URI'];更新
由于某种原因,nginx 不喜欢标头名称中的符号 '_',之前不知道它是如何工作的,也许在 nginx 更新后发生了一些变化.现在我正在使用
for some reason nginx don't like symbol '_' in header name, don't know how it worked before, maybe something changed after nginx update. Now i'm using
proxy_set_header rewriteduri $request_uri;在 php 中
$_SERVER['HTTP_REWRITEDURI']更多推荐
Apache 重写
发布评论