The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

PATH_INFO problem

ekstro's Avatar


25 Jan, 2012 09:28 PM


I really like Slim, thanks for doing that!

I have one problem with my webserver configuration and Slim. Domain is connected to main dir and htaccess redirects requests to correct location - something like that:

RewriteCond %{HTTP_HOST} ^$ [NC]

RewriteCond %{REQUEST_FILENAME} !/www/

RewriteRule ^(.*)$ /www/$1 [L]

With that configuration and url: "" I get this PATH_INFO from Slim: "tions/1". I don't now if I did something wrong or another problem occured.

My solution for this problem - I edited file "Environment.php" and changed line:

$env['PATH_INFO'] = substr_replace($_SERVER['REQUEST_URI'], '', 0, strlen($env['SCRIPT_NAME']));



Why did you substract REQUEST_URI by length of SCRIPT_NAME?

  1. Support Staff 1 Posted by Josh Lockhart on 26 Jan, 2012 08:38 PM

    Josh Lockhart's Avatar
    1. Are you on the master or develop branch?
    2. Do you still have the problem if you prepend "RewriteBase /www" to your .htaccess file?
  2. 2 Posted by ekstro on 26 Jan, 2012 09:46 PM

    ekstro's Avatar
    1. Branch.
    2. Yes, still.
  3. 3 Posted by Devon Weller on 31 Jan, 2012 03:51 PM

    Devon Weller's Avatar

    I had a similar problem with the SCRIPT_NAME not coming through correctly to PHP.

    My rewrite rules are inside an apache VirtualHost directive. Because of this, I had to use an absolute URL. To get this to work, I had to add the PT (passthrough) directive.

    This is my apache config that worked for me:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /index.php [QSA,L,PT]
  4. 4 Posted by merlijn on 28 Feb, 2012 07:24 AM

    merlijn's Avatar

    Ran into the same problem. Using the 1.6.0 release branch.
    Simply using:

        $env['PATH_INFO'] = $_SERVER['PATH_INFO'];
        $env['SCRIPT_NAME'] = $_SERVER['SCRIPT_NAME'];

    Works fine (in Enviroment.php).

  5. 5 Posted by merlijn on 23 Apr, 2012 12:45 PM

    merlijn's Avatar

    bump... problem still exists in 1.6.2 release.

  6. Support Staff 6 Posted by Josh Lockhart on 23 Apr, 2012 12:54 PM

    Josh Lockhart's Avatar

    Are /www and /www/ both beneath your public document root? If so, I'd keep all Slim files and the Slim .htaccess in the /www/ directory and uncomment the RewriteBase directive.

    Perhaps I'm not entirely sure how your filesystem structure is setup.

  7. 7 Posted by merlijn on 23 Apr, 2012 02:18 PM

    merlijn's Avatar

    First of all thanks for the reply.

    I have a complete different setup as the original poster.
    I am still figuring out what is the best way to organize the api and how the file structure should look like.

    But for now I have the following structure:

    ---- default.api.php
    ---- administration.api.php
    ---- organisations.api.php
    ---- anotherdomain.api.hp
    ---- etc

    Each .api.php file runs 1 slim application providing routes applicable to that domain.

    The api expects the url to be formatted like:


    for example

    I have placed the following rule in .htaccess:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule ^(myProject1|myProject2|myProject3|myProject4)/([A-Za-z0-9-_]+)/(.*)$ $1/$2.api.php/$3 [QSA,L]

    RewriteBase is commented out.

    With Slim 1.6.2 out of the box the routing fails. in the $env variable the PATH_INFO is set to person/hello/world where it should be hello/world.
    With result Slim loading a 404.

    The simple solution for this is modifying Enviroment.php to simply use the $_SERVER values for PATH_INFO & SCRIPT_NAME.
    I am sure there are way more elegant solutions, but this seems to work for me.

  8. 8 Posted by Kevin Chen on 28 May, 2012 08:14 AM

    Kevin Chen's Avatar

    I got the same probs too and I made some modified to the code like below:

    $env['PATH_INFO'] = substr_replace($_SERVER['REQUEST_URI'], '', 0, strlen($env['SCRIPT_NAME']));


    $env['PATH_INFO'] = substr($_SERVER['REQUEST_URI'], 0, strlen($env['SCRIPT_NAME'])) == $env['SCRIPT_NAME'] 
        ? substr_replace($_SERVER['REQUEST_URI'], '', 0, strlen($env['SCRIPT_NAME'])) : $_SERVER['REQUEST_URI'] ;
  9. 9 Posted by schmod on 14 Jun, 2012 05:30 PM

    schmod's Avatar

    I'm having a similar issue. My PATH_INFO is being truncated, and simply using the REQUEST_URI value within the _SERVER variable seems to work just fine for me:

    $env['PATH_INFO'] = $_SERVER['REQUEST_URI'];

    This snippet of a var_dump of my environment object should give you a good idea of what's going on...

          protected 'properties' => 
            array (size=23)
              'REQUEST_METHOD' => string 'GET' (length=3)
              'REMOTE_ADDR' => string '' (length=9)
              'SCRIPT_NAME' => string '/php' (length=4)
              'PATH_INFO' => string '/loWorld' (length=8)
              'QUERY_STRING' => string '' (length=0)
              'SERVER_NAME' => string 'localhost' (length=9)
              'SERVER_PORT' => string '80' (length=2)
              'CONTENT_TYPE' => string '' (length=0)
              'CONTENT_LENGTH' => string '0' (length=1)
              'AUTH_TYPE' => string '' (length=0)
              'X_ORIGINAL_URL' => string '/HelloWorld' (length=11)
              'HOST' => string 'localhost' (length=9)
              'CONNECTION' => string 'keep-alive' (length=10)
              'slim.url_scheme' => string 'http' (length=4)
              'slim.input' => string '' (length=0)
              'slim.errors' => resource(14, stream)

    Oh, and I'm using PHP 5.4.3 and IIS7.

  10. 10 Posted by schmod on 14 Jun, 2012 09:49 PM

    schmod's Avatar

    (Also, this wasn't an issue in 1.5.0)

  11. Support Staff 11 Posted by Andrew Smith on 16 Jun, 2012 12:59 AM

    Andrew Smith's Avatar

    A patch was created for this, it will be in the 1.6.3 branch.

  12. Brian Nesbitt closed this discussion on 29 Jun, 2012 01:14 PM.

  13. merlijn re-opened this discussion on 18 Oct, 2012 12:20 PM

  14. 12 Posted by merlijn on 18 Oct, 2012 12:20 PM

    merlijn's Avatar

    in 2.1.0 this is still an issue.

  15. Support Staff 13 Posted by Andrew Smith on 19 Oct, 2012 04:27 AM

    Andrew Smith's Avatar

    Please state which server you are testing on and show a sample of your code that has the issue occurring.

  16. 14 Posted by juanes on 19 Oct, 2012 11:28 AM

    juanes's Avatar
  17. 15 Posted by Sari4 on 19 Oct, 2012 03:59 PM

    Sari4's Avatar

    I'm impressed of , I need to say. Really not often do I encounter a phorum that's each educative and entertaining, and let me inform you, you have got hit the nail on the head. Your concept is outstanding; the difficulty is one thing that not sufficient people are speaking intelligently about. I'm very blissful that I stumbled throughout this in my seek for something regarding this. Sending my regards

  18. 16 Posted by merlijn on 19 Oct, 2012 04:54 PM

    merlijn's Avatar

    Sorry, I have been out of the office the last days.

    Server is:
    Server version: Apache/2.2.22 (FreeBSD)
    Server built: Aug 9 2012 16:06:10
    Server's Module Magic Number: 20051115:30
    Server loaded: APR 1.4.5, APR-Util 1.3.12
    Compiled using: APR 1.4.5, APR-Util 1.3.12
    Architecture: 64-bit
    Server MPM: Prefork
      threaded: no
        forked: yes (variable process count)
    Server compiled with....
     -D APACHE_MPM_DIR="server/mpm/prefork"
     -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)

    FreeBSD 8.2-RELEASE-p10

    Setup hasn't changed from

    I will post a code example soon.

  19. Support Staff 17 Posted by Brian Nesbitt on 31 Oct, 2012 03:17 AM

    Brian Nesbitt's Avatar
  20. 18 Posted by merlijn on 01 Nov, 2012 07:47 AM

    merlijn's Avatar

    Very true, it's exactly the reason as described in that thread.
    There are however, very good reasons to implement Slim in such way.



  21. Andrew Smith closed this discussion on 20 Nov, 2012 11:33 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac