dongqiyang3711 2016-07-25 09:26 采纳率: 100%
浏览 470
已采纳

ProxyPass和ProxyPassReverse - 从浏览器地址栏获取原始URL

我创建了两个网站( http://localhost/webone, http://localhost/webtwo).

第二个网站具有如下网址: http://localhost/webtwo/webone (使用ProxyPass和ProxyPassReverse)

如果我们转到上面的URL,上面就将会显示网络内容。 现在,如果有人访问一个Web,那么我想捕获用户访问URL。(可以是http:// localhost / webone或http:// localhost / webtwo / webone) 我的问题是: 如果有人从http:// localhost / webtwo / webone URL访问第二个网站。 然后,如果我执行以下代码,它将返回http:// localhost / webone。.

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

但是浏览器显示的URL是http://localhost/webtwo/webone. 有人可以建议一种捕获URL的方法吗?http://localhost/webtwo/webone

  • 写回答

3条回答 默认 最新

  • donglin1192 2016-07-27 14:49
    关注

    You can add your custom request header by using RequestHeader directive to request headers list (right after ProxyPass*):

    RequestHeader add X-REQUEST-URI "expr=%{HTTP_HOST}%{REQUEST_URI}"
    

    This way you will have a header named HTTP_X_REQUEST_URI, a holder of requested URI and is accessible via $_SERVER['HTTP_X_REQUEST_URI']:

    'HTTP_X_REQUEST_URI' => string 'localhost/webtwo/webone' (length=23)
    

    Also there are some headers which are set by mod_proxy and you may find useful. From apache.org:

    When acting in a reverse-proxy mode (using the ProxyPass directive, for example), mod_proxy_http adds several request headers in order to pass information to the origin server. These headers are:

    X-Forwarded-For The IP address of the client.

    X-Forwarded-Host The original host requested by the client in the Host HTTP request header.

    X-Forwarded-Server The hostname of the proxy server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建