Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have PHP 7.1 and apache 2.4 running in a docker vm. I have mod rewrite enabled. I have code that needs $_SERVER['SCRIPT_URL'] and $_SERVER['SCRIPT_URI']. These are not set. I created a minimal example that proves it. Do the following in bash:

git clone https://github.com/zippy1981/php7-mod_rewrite.git
cd php7-mod_rewrite
docker-compose stop && docker-compose rm -fv &&  docker-compose build --force-rm --no-cache && docker-compose up -d
curl localhost:8080/foo

That redirect is enabled by the .htaccess line RewriteRule ^foo$ app.php proving mod_rewrite is installed, enabled, and is touching this particular request. That url returns a JSON version of $_SERVER that looks like this:

{
    "_SERVER": {
    "REDIRECT_STATUS": "200",
    "HTTP_HOST": "localhost:8080",
    "HTTP_USER_AGENT": "curl\/7.47.0",
    "HTTP_ACCEPT": "*\/*",
    "PATH": "\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin",
    "SERVER_SIGNATURE": "<address>Apache\/2.4.10 (Debian) Server at localhost Port 8080<\/address>\n",
    "SERVER_SOFTWARE": "Apache\/2.4.10 (Debian)",
    "SERVER_NAME": "localhost",
    "SERVER_ADDR": "172.24.0.2",
    "SERVER_PORT": "8080",
    "REMOTE_ADDR": "172.24.0.1",
    "DOCUMENT_ROOT": "\/var\/www\/html",
    "REQUEST_SCHEME": "http",
    "CONTEXT_PREFIX": "",
    "CONTEXT_DOCUMENT_ROOT": "\/var\/www\/html",
    "SERVER_ADMIN": "webmaster@localhost",
    "SCRIPT_FILENAME": "\/var\/www\/html\/app.php",
    "REMOTE_PORT": "49122",
    "REDIRECT_URL": "\/foo",
    "GATEWAY_INTERFACE": "CGI\/1.1",
    "SERVER_PROTOCOL": "HTTP\/1.1",
    "REQUEST_METHOD": "GET",
    "QUERY_STRING": "",
    "REQUEST_URI": "\/foo",
    "SCRIPT_NAME": "\/app.php",
    "PHP_SELF": "\/app.php",
    "REQUEST_TIME_FLOAT": 1483412792.892,
    "REQUEST_TIME": 1483412792,
    "argv": [],
    "argc": 0
    }
}

This does not have the SCRIPT_URI or SCRIPT_URL environment variables in it. How do I get them to show up?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.