在 php 脚本中访问重写的 URI
所以我有一个 .htaccess 文件,它正在执行从 /testscript1.php/testvar1/testvar2 的重写 /testscript2.php/testvar3/testvar4 (这是一个过于简化的例子,但你明白了)。
现在,虽然在我的 testscript2.php 脚本中,当我访问 $_SERVER['REQUEST_URI'] 变量时,我看到 /testscript1.php/testvar1/testvar2 而不是 /testscript2.php/testvar3/testvar4 ,这就是我正在寻找的。即 $_SERVER['REQUEST_URI'] 包含重写之前的 uri。
我的问题很简单,有没有办法访问重写的uri?
So I have a .htaccess file which is performing a rewrite from /testscript1.php/testvar1/testvar2 to
/testscript2.php/testvar3/testvar4
(this is an over simplification but you get the idea).
Now though in my testscript2.php script when i access the $_SERVER['REQUEST_URI'] variable i see /testscript1.php/testvar1/testvar2 rather than /testscript2.php/testvar3/testvar4 which is what I am looking for. i.e $_SERVER['REQUEST_URI'] contains the uri before the rewrite.
My question is simply, is there a way to access the rewritten uri?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
phpinfo()
来查看$_SERVER
在重写的页面上的外观。 Apache 提供了大量可能有用的信息。在我的测试服务器上,我得到以下内容可能会对您有所帮助:
我希望至少其中一个或其中的组合应该能够可靠地为您提供您正在寻找的信息。
干杯。
Try using
phpinfo()
to get a view on what$_SERVER
looks like on a rewritten page. Apache supplies quite a lot of info that may be useful.On my test server, I get the following which may help you:
I would expect that at least one or a combination of those should be able to reliably give you the information you're looking for.
Cheers.
如果您使用路径信息来传递附加路径,则可以从PHP_SELF中删除该后缀:
或者直接使用SCRIPT_NAME,因为 >PHP_SELF = SCRIPT_NAME + PATH_INFO。只需查看
$_SEVER
中的各种值即可。If you’re using the path info to pass an additional path, you can strip that suffix from PHP_SELF:
Or simply use SCRIPT_NAME since PHP_SELF = SCRIPT_NAME + PATH_INFO. Just take a look at the various values in
$_SEVER
.