$_SERVER['REQUEST_URI'] returns full URL instead of path to script

前端 未结 3 1064
死守一世寂寞
死守一世寂寞 2021-01-22 12:52

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

相关标签:
3条回答
  • 2021-01-22 13:09

    Had the same issue recently,
    My solution:
    Firstly check if your http://localhost has the same effect.(which i see i didn't)
    If not then added your virtual host(domains) to /etc/host file.

    Hope this is helpful.

    0 讨论(0)
  • 2021-01-22 13:23

    I believe you're receiving the desired effect of creating a virtual host:

    No Virtual Host:

    /ivankristianto/request.php 
    

    With Virtual Host:

    http://www.ivankristianto.local/request.php
    

    http://www.ivankristianto.local - I think this seems wrong to you because it contains http://www and .local - you could change this to just invankristano and your REQUEST_URI would output the same as if you had no virtual host. It's representing the path to your request.php - that you've set in the hosts file and is therefore valid part of the URI.

    So basically what I'm saying is there's nothing wrong.

    If it's causing you problems, then one solution would be to determine which environment you're in - e.g

    if($_SERVER['HTTP_HOST'] == 'www.ivankristianto.local') {
        $dev_env = TRUE;
    }else {
        $dev_env = FALSE;
    }
    

    then somewhere use that:

    if($dev_env) {
        $_SERVER['REQUEST_URI'] = str_replace($_SERVER['HTTP_HOST'],'',$_SERVER['REQUEST_URI']);
    }
    

    update

    try changing host conf to:

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

    (remove www. from ServerName)

    0 讨论(0)
  • 2021-01-22 13:28

    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.

    0 讨论(0)
提交回复
热议问题