Apache 重写

编程入门 行业动态 更新时间:2024-10-26 10:28:46
本文介绍了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 重写

本文发布于:2023-11-02 08:36:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551912.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   Apache

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!