Apache重写-在PHP中获取原始URL [英] Apache rewrite - get original URL in PHP

查看:72
本文介绍了Apache重写-在PHP中获取原始URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为此地址在nginx或Apache中进行了重写:

I have a rewrite in nginx or Apache for this address:

http://domain.com/hello

像这样的脚本

http://domain.com/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 http://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重写-在PHP中获取原始URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆