gpt4 book ai didi

php - Apache 重写 - 在 PHP 中获取原始 URL

转载 作者:IT王子 更新时间:2023-10-29 00:17:21 25 4
gpt4 key购买 nike

我在 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;
}
}

最佳答案

这实际上取决于 PHP 设置。使用 mod_php,您通常仍然在 REQUEST_URI 中拥有原始请求路径。对于 CGI 或 FastCGI 设置,它通常是 REDIRECT_URL。您必须检查 phpinfo() 页面才能确定。

如果您真的找不到任何有用的东西,那么就该作弊了!您可以像这样调整您的 RewriteRule,以在您选择的环境变量中保留原始 URL:

RewriteRule ^(\w+)$   test.php?ref=$1    [E=ORIG_URI:/$1]

这将作为 $_SERVER["ORIG_URI"] 提供,或者您可以使用 $_GET['ref'] 从 URI 中获取它。但是您必须对所有潜在的 RewriteRules 使用这个技巧。

关于php - Apache 重写 - 在 PHP 中获取原始 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5493075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com