$ _SERVER ['REQUEST_URI']返回完整的URL,而不是脚本的路径 [英] $_SERVER['REQUEST_URI'] returns full URL instead of path to script

查看:412
本文介绍了$ _SERVER ['REQUEST_URI']返回完整的URL,而不是脚本的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PHP应用程序由于$ _SERVER ['REQUEST_URI']而无法正常运行,因此将完整的URL而不是相对路径返回给脚本.

My PHP app is not working because of $_SERVER['REQUEST_URI'] returns the full url to the script instead of a relative path.

我的环境:
Windows 7 64位.
XAMPP版本1.8.2
PHP版本5.4.16
Apache版本Apache/2.4.4(Win32)OpenSSL/0.9.8y PHP/5.4.16

My environment:
Windows 7 64 bit.
XAMPP Version 1.8.2
PHP Version 5.4.16
Apache Version Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.16

我的虚拟主机配置:

<VirtualHost *:80>
DocumentRoot "D:/HTDOCS/ivankristianto"
ServerName www.ivankristianto.local
UseCanonicalName Off
<Directory "D:/HTDOCS/ivankristianto">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Require all granted
</Directory>
</VirtualHost>

我创建了一个基本脚本来测试$ _SERVER的内容:

I created a basic script to test the $_SERVER content:

echo '$_SERVER[\'HTTP_HOST\'] : ' . $_SERVER['HTTP_HOST'];
echo '<br/>' . '$_SERVER[\'PHP_SELF\'] : ' . $_SERVER['PHP_SELF'];
echo '<br/>' . '$_SERVER[\'REQUEST_URI\'] : ' . $_SERVER['REQUEST_URI'];

结果如下:

// URL: http://localhost/ivankristianto/request.php
$_SERVER['HTTP_HOST'] : localhost
$_SERVER['PHP_SELF'] : /ivankristianto/request.php
$_SERVER['REQUEST_URI'] : /ivankristianto/request.php //This is correct

// URL: http://www.ivankristianto.local/request.php
$_SERVER['HTTP_HOST'] : www.ivankristianto.local
$_SERVER['PHP_SELF'] : /request.php
$_SERVER['REQUEST_URI'] : http://www.ivankristianto.local/request.php  //This is wrong

我没有使用任何代理,我只是在/etc/hosts中设置了它.

I didn't use any proxy, all I did is just set it in my /etc/hosts.

我已经花费了数小时来找出发生这种情况的原因,并且已经通过Google和该网站进行了搜索,但是找不到任何线索.

I have spent hours to find out why this is happens and have been search through google and this website, but cannot find any clue.

能否请您指出我的问题所在?

Can you please point me out what's wrong?

谢谢.
伊万

推荐答案

我终于开始使用它了.
这是我所做的步骤(我不知道为什么会生效,但是现在可以正常运行).

I finally got it working.
Here is the steps i did ( i don't know why it is effected, but it is working now ).

  1. 在xampp上安装PHP Fastcgi,我按照以下步骤操作: https://commaster.net/content/installing-php-fastcgi-and-zend-opcache-xampp-windows
  2. 我加载了mod_fcgid,但是我没有使用php-cgi.exe处理程序
  3. 使用此命令ipconfig/flushdns更新我的/etc/hosts文件并刷新dns
  4. 重新启动apache
  1. Install PHP Fastcgi on xampp, i follow this steps: https://commaster.net/content/installing-php-fastcgi-and-zend-opcache-xampp-windows
  2. I load the mod_fcgid, but i don't use php-cgi.exe handler
  3. Update my /etc/hosts file and flush dns with this command ipconfig /flushdns
  4. Restart apache

它正在以某种方式起作用.
老实说,我不知道为什么它起作用,但是如果有人遇到同样的问题,我希望该解决方案可能会有所帮助.

And it is working somehow.
Honestly i don't know why it is working, but if someone stumble the same problem, i hope the solution might help.

这篇关于$ _SERVER ['REQUEST_URI']返回完整的URL,而不是脚本的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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