dongshanni1611 2014-10-05 06:00
浏览 70
已采纳

$ _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.

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

My Virtual Host Conf:

<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>

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'];

And here is the result:

// 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

And

// 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

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

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?

Thanks.
Ivan

  • 写回答

3条回答 默认 最新

  • doubi2014 2014-10-07 15:03
    关注

    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. 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.

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

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集