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

No way to make Slim work in a subdir

Alex's Avatar


28 Dec, 2013 02:34 PM

Hi All!

my project dir structure is like this:

-src/vendors/slim {and other composer libs}

in the .htaccess i have

RewriteRule ^api/v1/(.*)$ apps/Api/v1/index.php [QSA,L]

the website is running on Apache2 with Php 5.4.3

Simply there is no way to make the apps/Api/v1/index.php to work...
neither the following snippets are working, both fails to 404 without errors. i've put an echo before and after and i can see the ouput of that echo, but Slim refuse to recognize the path.

echo "s10";
$app->get('/hello/', function () {
    echo "Hello";
$app->get('/api/v1/hello/', function () {
    echo "Hello";
echo "s20";

this is what i get at localhost/api/v1/hello

404 Page Not Found

is it normal? is there any solution?

  1. 1 Posted by uwe.d.wagner on 30 Dec, 2013 08:23 AM

    uwe.d.wagner's Avatar

    Could you try $app->get('/hello', .... without slash? /hello and /hello/ are different routes.

  2. 2 Posted by Alex on 30 Dec, 2013 10:38 AM

    Alex's Avatar

    I've not mentioned it but i've tried it in all that ways.
    It seems very strange because adding

    echo "s10";
    $app->get('/', function () {
        echo "Hello";

    to the file, the url
    works perfect. So i think the problem is in detecting the path (don't know if a bug in Slim or in my config).

    anyway i've opened an issue on GitHub

  3. 3 Posted by Pierre on 30 Dec, 2013 01:20 PM

    Pierre's Avatar

    I think it is a problem with the rewrite module, I also had some troubles to get it working. I use the Directory directive in the corresponding virtual host section of my apache config. Assuming the document root is /var/www/html/apps for example,

    #LogLevel alert rewrite:trace6 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L]

    The LogLevel directive is for apache 2.4, it helps to debug rewrite rules but for lower version of apache you should check on apache documentation how to turn on logging..

  4. 4 Posted by Pierre on 30 Dec, 2013 01:26 PM

    Pierre's Avatar

    Sorry, my code was not escaped, so a part is missing. Here it is again.

    <Directory /var/www/html/apps/api/v1>
        #put here the rewrite rules
       RewriteEngine On
       RewriteCond %{REQUEST_FILENAME} ! -f
       RewriteRule ^ index.php [QSA,L]

    Instead of Directory directive, maybe it would be better to use the Location directive

  5. 5 Posted by Alex on 30 Dec, 2013 02:25 PM

    Alex's Avatar

    Hi Pierre,
    i've already enabled the rewrite loggin to check it was working good...
    unfortunately i wasn't able to investigate further in sourcecode of Slim to discover why it can't recognize the url pattern... i would really like to know how SLIM try to get the current requested url (that should be passed by the mod_rewrite) as i think here could be the problem.
    In the reqrite rule there is NO param to forward the requested url to the index.php script... so if in someway mod_rewrite is not passing that original url to Slim it really couldn't recognize it.

    i've added this to index.php (as in the documentaton samples)

    $app->get('/hello/:name', function ($name) {
        echo "Hello, $name";

    this is my Rewrite Log for project.loc/hello/kkk - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fd13e60a0/initial [perdir /mnt/hgfs/project-www/src/] add path info postfix: /mnt/hgfs/project-www/src/hello -> /mnt/hgfs/project-www/src/hello/kkk - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fd13e60a0/initial [perdir /mnt/hgfs/project-www/src/] strip per-dir prefix: /mnt/hgfs/project-www/src/hello/kkk -> hello/kkk - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fd13e60a0/initial [perdir /mnt/hgfs/project-www/src/] applying pattern '^api/v1/(.*)$' to uri 'hello/kkk' - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fd13e60a0/initial [perdir /mnt/hgfs/project-www/src/] add path info postfix: /mnt/hgfs/project-www/src/hello -> /mnt/hgfs/project-www/src/hello/kkk - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fd13e60a0/initial [perdir /mnt/hgfs/project-www/src/] strip per-dir prefix: /mnt/hgfs/project-www/src/hello/kkk -> hello/kkk - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fd13e60a0/initial [perdir /mnt/hgfs/project-www/src/] applying pattern '^(.*)$' to uri 'hello/kkk' - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fd13e60a0/initial [perdir /mnt/hgfs/project-www/src/] rewrite 'hello/kkk' -> 'apps/Api/v1/index.php' - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fd13e60a0/initial [perdir /mnt/hgfs/project-www/src/] add per-dir prefix: apps/Api/v1/index.php -> /mnt/hgfs/project-www/src/apps/Api/v1/index.php - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fd13e60a0/initial [perdir /mnt/hgfs/project-www/src/] strip document_root prefix: /mnt/hgfs/project-www/src/apps/Api/v1/index.php -> /apps/Api/v1/index.php - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fd13e60a0/initial [perdir /mnt/hgfs/project-www/src/] internal redirect with /apps/Api/v1/index.php [INTERNAL REDIRECT] - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fc60ac7d8/initial/redir#1 [perdir /mnt/hgfs/project-www/src/] strip per-dir prefix: /mnt/hgfs/project-www/src/apps/Api/v1/index.php -> apps/Api/v1/index.php - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fc60ac7d8/initial/redir#1 [perdir /mnt/hgfs/project-www/src/] applying pattern '^api/v1/(.*)$' to uri 'apps/Api/v1/index.php' - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fc60ac7d8/initial/redir#1 [perdir /mnt/hgfs/project-www/src/] strip per-dir prefix: /mnt/hgfs/project-www/src/apps/Api/v1/index.php -> apps/Api/v1/index.php - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fc60ac7d8/initial/redir#1 [perdir /mnt/hgfs/project-www/src/] applying pattern '^(.*)$' to uri 'apps/Api/v1/index.php' - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fc60ac7d8/initial/redir#1 [perdir /mnt/hgfs/project-www/src/] rewrite 'apps/Api/v1/index.php' -> 'apps/Api/v1/index.php' - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fc60ac7d8/initial/redir#1 [perdir /mnt/hgfs/project-www/src/] add per-dir prefix: apps/Api/v1/index.php -> /mnt/hgfs/project-www/src/apps/Api/v1/index.php - - [30/Dec/2013:14:11:13 +0000] [project.loc/sid#7f7fd15a15f8]rid#7f7fc60ac7d8/initial/redir#1 [perdir /mnt/hgfs/project-www/src/] initial URL equal rewritten URL: /mnt/hgfs/project-www/src/apps/Api/v1/index.php [IGNORING REWRITE]

    and the result is "s10s20Hello" (that's the default result for the "/" route!)

    ps. project.loc is the virtualhost name.

    and the result of project.loc/api/v1/hello/kkk is
    s10s20 404 Page Not Found

    the rewrite log is about identical...

    thanks anyway for the interest.

  6. 6 Posted by pierre on 30 Dec, 2013 10:08 PM

    pierre's Avatar

    Since it gets into the index.php, it means your rewrite rule is active. But the parameters don't seem to be passed to the index.php

    You can do a dump of the $_SERVER variable to see the full URI ? Or you can use the methods on the request to help understand how the url is rewritten ? For example put this in your index.php

     $req = $app->request();
     $resourceUri = $req->getResourceUri();
     echo "<br>" . $resourceUri . "</b>";
    Check in Request.php, you can also use getRootUri(), and others.

    In any case, I had the same problem as you but I did not investigate much because with the Directory directive I could keep the simplest rewrite rule possible.

  7. Support Staff 7 Posted by Andrew Smith on 31 Dec, 2013 11:47 AM

    Andrew Smith's Avatar

    Slim should work in sub directory, we fixed this a few iterations back, if you can provide some more details, like which OS, version of Slim (find this in the Slim.php class) and if possible an example of the project that is breaking on github or something.

  8. 8 Posted by Alex on 02 Jan, 2014 08:34 AM

    Alex's Avatar


    For what i know the Directory directive (i'm already using in the vhost config) couldn't be the solution as it just serves to same settings you would set in a .htaccess . in my case the Directory directive in the vhost contain the "override all" line so that the the .htaccess in the root folder have permission to override all settings/directives... so its just like as what i wrote in my .htaccess would be wrote in the vhost config file. If i'm wrong on this please tell me.

    Anyway i've tested your code (thanks for it!) and this is the result when i visited this url: project.loc/api/v1/hello/kkk

    Array ( [REDIRECT_STATUS] => 200 [HTTP_HOST] => project.loc [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_ACCEPT_LANGUAGE] => it-it,it;q=0.8,en-us;q=0.5,en;q=0.3 [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_COOKIE] => _ga=GA1.2.709058695.1387369968 [HTTP_CONNECTION] => keep-alive [PATH] => /usr/local/bin:/usr/bin:/bin [SERVER_SIGNATURE] =>
    Apache/2.2.22 (Debian) Server at project.loc Port 80
    [SERVER_SOFTWARE] => Apache/2.2.22 (Debian) [SERVER_NAME] => project.loc [SERVER_ADDR] => [SERVER_PORT] => 80 [REMOTE_ADDR] => [DOCUMENT_ROOT] => /mnt/hgfs/project-www/src [SERVER_ADMIN] => webmaster@localhost [SCRIPT_FILENAME] => /mnt/hgfs/project-www/src/apps/Api/v1/index.php [REMOTE_PORT] => 57926 [REDIRECT_URL] => /hello/kkk [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => /hello/kkk [SCRIPT_NAME] => /apps/Api/v1/index.php [PHP_SELF] => /apps/Api/v1/index.php [REQUEST_TIME_FLOAT] => 1388651123.006 [REQUEST_TIME] => 1388651123 )

    As you can see

    [REQUEST_URI] => /hello/kkk

    but the final line generated by

    echo "<br>" . $resourceUri . "<br>";
    is simply
  9. 9 Posted by pierre on 02 Jan, 2014 09:56 AM

    pierre's Avatar

    @Alex: I think you are right, the .htaccess (I have never used .htaccess) should do the same as the Directory directive.

    In fact I have the same problem as you, when I put the site in a subdir and then compare what is in $_SERVER and what is in request()->getResourceUri(), I see that slim misses a part of the request.

    Since I have changed my set-up in between (I have put the API part, in PHP, in a different document_root than the client/javascript side of the site) I don't suffer from the problem anymore. Probably Andrew can help you better !

    rgds, P

  10. 10 Posted by Alex on 02 Jan, 2014 10:24 AM

    Alex's Avatar

    @pierre thanks for the help!

    @andrew i've tested the system on both WAMP (Win7) and Debian7 with the same results. actually, all test i've posted here was made on Debian - Slim 2.4

    It's actually a bit time-taking create a new project and post it on github but i will do the possible. The fact is that in this conditions i'm thinking to switch away from slim also because my project will get bigger and Slim could become too small on the long term. Anyway i'm still interested in Slim as i wish to use it for other projects so i will do the possible to help to fix this bug (if it is a bug).
    Anyway it's really not very complex. i've just set my root folder in apache to src/ put in the .htaccess posted before and created the index.php in src/api/v1/ ... nothing more.

  11. 11 Posted by charlie.schlies... on 03 Jan, 2014 02:01 AM

    charlie.schliesser's Avatar

    Hey Alex,

    It looks like the problem is happening in Slim/Environment.php on line 143:


    $requestUri = '/foo/api/v1/hello';
    $physicalPath = '/foo/apps/Api/v1';

    Then line 143 runs:
    $env['PATH_INFO'] = substr_replace($requestUri, '', 0, strlen($physicalPath)); // <-- Remove physical path

    And $env['PATH_INFO'] is now o. This environment variable ($env['PATH_INFO']) is what your $app->get() method checks against.

    After playing with this code a bit and looking at the $_SERVER variables that are available, it might be difficult to accommodate your specific folder setup. Do you have to have /api/ and /apps/api in separate folders? i.e. can you just have /api/v1/index.php and then route http://localhost/api/v1/hello?

  12. 12 Posted by charlie.schlies... on 03 Jan, 2014 02:13 AM

    charlie.schliesser's Avatar

    Actually, you could override the $_SERVER['REQUEST_URI'] in your apps/api/v1/index.php like so:

    require '../../../vendor/autoload.php';
    $_SERVER['REQUEST_URI'] = str_replace('/foo/api/v1/', '/foo/Apps/api/v1/', $_SERVER['REQUEST_URI']);
    $app = new \Slim\Slim(array());
    $app->get('/hello', function () {
        echo "Hello";

    This is a bit hackish, but I think that for your needs there would have to be a change to how the Environment class splits up the request from the script path.

  13. Support Staff 13 Posted by Andrew Smith on 03 Jan, 2014 03:07 AM

    Andrew Smith's Avatar

    I just tested this on WAMP with the develop branch and can't replicate this issue. Most of the fixes that were made on the develop branch to do with Environment.php and subdir are in 2.4.0. Also just noted your .htaccess rule seem to be looking for the wrong directory since this is case sensitive.

    You have Api with capital A, while your directory name is lowercase.

    RewriteRule ^api/v1/(.*)$ apps/Api/v1/index.php [QSA,L]

  14. 14 Posted by Alex on 03 Jan, 2014 09:47 AM

    Alex's Avatar

    @charlie.schlisser Thanks much for the help! so the culprit was Slim/Environment.php ... that code block is something easily fixable.

    Anyway regarding the fact if i have to mantain my actual folder structure the answer is yes and no... in the sense that the actual folder structure is some kind of standard way to mantain multi-layer/module projects like many other PHP frameworks do... so it's not that i have to, but that i would like to... For projects where the hosting service allow it, maybe is more confortable to split the virtual-host and point one of them directly in the apps/api/v1 folder so that index.php result to be in the root. Thanks again also for the second hack-fix code!

    @Andrew the capital letter in the .htaccess is right, i had mistyped it inthe first post but now i've just updated it. i've just edited the main post . I'll try to download the develop branch of Slim to check if this problem is fixed there. I've also used Wamp for a lot of time, but experiece teached me that dev and tests have to be ever done on enviorinments about identical to production because what works on Wamp many time don't work on real Linux system and the first 2 reasons are Permissions and Casing. I'll have a try! Thanks much!

  15. 15 Posted by charlie.schlies... on 04 Jan, 2014 10:37 PM

    charlie.schliesser's Avatar

    I also recommend trying the develop branch, but you may run into other issues as it's in heavy development at the moment. If that's the case, running 2.4 (current master) and changing the request URI might be the safest bet.

    Regarding your comments about dev and production environments – there's quite an awesome conversation to be had there, but might I briefly recommend you look into running a virtual machine. VMWare Player is free on Windows and would let you run a simple stack (for example, Ubuntu with Apache, PHP, & MySQL is really quick to get up and running). It won't be identical to the production environment, but at least you'll be developing on a much similar platform. Just an idea. If you want to discuss feel free to hit me up.

  16. 16 Posted by Harold Kyle on 05 Feb, 2014 05:07 AM

    Harold Kyle's Avatar

    These solutions to the Environment problems seem hackish. Simply, there should be a way to override the Environment variables because Slim can't anticipate all server configurations. The changes to the hard-coded determination of the PATH_INFO broke all routes on our installation when we upgraded Slim 2.3 to 2.4.

    We're running into a similar situation (on nginx) where our script is running from a rewritten URL, completely different from the actual Request URI. As a result this code wipes out the Request URI entirely when setting the PATH_INFO (upon which all routes are determined), and all our routes are set to "/".

    This would all be manageable if there were a way to override it without overriding $_SERVER variable and introducing unpredictable changes downstream. It looks like the code of the Environment.php was written with the idea of passing in some custom user preferences or server configurations, but I don't see documentation for this and it doesn't seem to be fully implemented.

    In our installation we are rolling back to 2.3 but I wanted to alert you to the dangers of the hard-coded Environment variables. Or am I missing something?

  17. Support Staff 17 Posted by Andrew Smith on 07 Feb, 2014 04:00 PM

    Andrew Smith's Avatar

    Hi Harold, I am still unable to replicate the error that keep getting mentioned here, can you or someone else create a Vagrant box with this setup so I can investigate it more. Otherwise it is a bit hard to work out what the issue is that everyone is experiencing. I currently use Slim on various platforms and even with setup of it being in a subdirectory and have no issue at all. (Platforms include Windows, Linux [Ubuntu] and OSX)

  18. 18 Posted by harold on 07 Feb, 2014 05:19 PM

    harold's Avatar

    Thanks for responding to this issue. As a first step, perhaps I could just share with you the relevant server config and PHP server variables. I think you could achieve this by forcing the $_SERVER['SCRIPT_NAME'] variable to be a certain value before you initialize Slim. I believe that pre-2.4 Slim supported rewriting URLs from any directory. The code for the physical path introduced in 2.4 seems to require that the script name bear some relation to the request URI. This isn't always the case, as in my setup:

    nginx configuration

    In the .conf file:

    location ~ ^/rest/(.*)$ {
        rewrite ^.* /wp-content/plugins/my-rest-plugin/index.php?$args;
    In the fastcgi_params file:
    fastcgi_param    SCRIPT_NAME     $fastcgi_script_name;
    fastcgi_params  REQUEST_URI     $request_uri;


    echo $_SERVER[SCRIPT_NAME]; // /wp-content/plugins/my-rest-plugin/index.php <-- here's a value you might not have expected
    echo $_SERVER[REQUEST_URI]; // /rest/papers

    I believe I am setting the $_SERVER variables in a standard way, but you can see that the request path has nothing in common with the script name. So here is where the problem lies:

    $physicalPath = str_replace('\', '', dirname($scriptName)); // <-- With rewriting
    $physicalPath becomes /wp-content/plugins/my-rest-plugin, and then gets a trailing slash in the next line. So we hit this:
    $env['PATH_INFO'] = substr_replace($requestUri, '', 0, strlen($physicalPath)); // <-- Remove physical path
    //substr_replace('/rest/papers', '', 0, 35) returns "", so downstream I have no current route
    Request URLs are sometimes rewritten to completely different scripts, perhaps not just in a subdirectory, as in my case. Beyond my specific case, it would help if there were a way to pass in preferences for the Environment's PATH_INFO when intializing Slim, to override the hard-coded dependancies on certain $_SERVER values.
  19. 19 Posted by harold on 08 Feb, 2014 03:06 AM

    harold's Avatar

    I've been able to get Slim 2.4 working by overriding the $env['PATH_INFO'] before the query string is stripped on line 144 of Environment.php.

    $env['PATH_INFO'] = substr_replace($requestUri, '', 0, strlen($physicalPath)); 
    $env['PATH_INFO'] = $_SERVER['REQUEST_URI']; // <-- this override works for me when added
    $env['PATH_INFO'] = str_replace('?' . $queryString, '', $env['PATH_INFO']); // <-- Remove query string
    This works for my setup but doesn't address the physicalPath that you're trying to extract in the code beforehand. (I'm not really sure how that's supposed to work).
  20. 20 Posted by jose_navas on 25 Feb, 2014 07:38 PM

    jose_navas's Avatar

    I also have trouble with making Slim work in a Subdirectory. I running a WAMP environment with the following structure:

        '-- MyApp/
                 - .htaccess
                 - index.php
        '-- AnotherApp/

    There is another folders like templates and vendor (where Slim is stored) inside MyApp, but when I run my Slim App, the routes get redirected as if my project is stored in the document root (htdocs):

    // new Slim App with default settings
    $app = new \Slim\Slim();
        'templates.path' => './templates'
    // home page
    $app->get('/', function () use ($app) {

    The only way I managed to make it work is adding the prefix (application's directory) of my application to the redirect method:

    This works, but I'm wondering if I move my Slim application to another directory, this will break inevitably...
    my other post explaining this better :)

  21. 21 Posted by jose_navas on 06 Mar, 2014 02:40 PM

    jose_navas's Avatar

    I'm using the standard .htaccess that comes with Slim.... Should I modify the .htaccess rewrite rules can resolve this issue? or is Slim internals related?


  22. 22 Posted by Juicetiger on 08 Apr, 2014 02:04 AM

    Juicetiger's Avatar


    Here is what I used to get Slim to work in a sub directory:
    dataStation is a sub dir off the root. Rewrite just needs a pattern to look for in the URL. I use rubular to create/test regex expressions. I am using XAMP for testing.

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(slim) slim/index.php [QSA,L]

    If your using Slim in nested sub dirs you have to escape the slashes
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(subdir1\/subdir2\/subdir3) slim/index.php [QSA,L]

    this will send any url matching subdir1/subdir2/subdir3 to slim/index.php

    Hope this helps

  23. 23 Posted by Peter on 08 May, 2014 07:23 PM

    Peter's Avatar
    1. Using Xamp the Slim - applications work fine .
    2. Moving the Slim- applications to hosting provider breaks the applications. Getting 404's .

    3 Please give me a simple solution , e.g. is it possible to use a directory structure without using .htaccess ????

    1. Was very content when all was working fine locally using Xamp, no thinking of moving on. Too many people are having this same problem.

    2. I don't mind hardcoding paths if it solves this , don't want to spend more days wasting time on this.

  24. 24 Posted by Dim on 07 Jul, 2014 01:56 PM

    Dim's Avatar

    I have the same problem. I've developed my application to xampp and works fine. However, when I transfer it to the remote server (ubuntu 12.04, Apache/2.4.9 Ubuntu, PHP 5.5.14-2) non of the routes works (404), except the default one:

    $app->get('/', function ()use ($app) { echo "this is the default page" });

    I've checked the permisions to the root folder as well as the apache2 logs for potential errors, however no solution can be achieved. Could someone help me more on this issue?

  25. 25 Posted by harold on 25 Jul, 2014 03:18 AM

    harold's Avatar

    I had written earlier about not being able to run Slim from a location whose URL did not match the "physical path" as determined by Environment.php. I had modified the core Environment file at the time, but this has been a hassle. I wish there were better documentation of the \Slim\Environment::mock() method, but here's the best I could come up with to adjust the PATH_INFO property without modifying the code Slim files:

    // The PATH_INFO environment variable for Slim relies on the "physicalPath", 
    // which doesn't work when using a rewritten URL. We can change this manually before our
    // app creates an instance.
    // first we need to trim the query string, as the Environment class constructor would do.
    // the differene here is we use the REQUEST_URI without trying to determine the physical path.
    $queryString = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''; 
    $path_info = str_replace('?' . $queryString, '', $_SERVER['REQUEST_URI']);

    // straight out of the Environment class constructor $path_info = '/' . ltrim( $path_info, '/');

    // extract the Environment properties as set in the class constructor. the "default" ones in // Environment::mock() are not to be relied on. For instance, "GET" is the hard-coded HTTP // method. Rather than duplicate the Envirorment constructor code, we'll extract its properties // as an ArrayObject through the public getIterator() method...the only way I can find. $env = \Slim\Environment::getInstance()->getIterator();

    // update the PATH_INFO of the properties set in the Environment class constructor $env->offsetSet('PATH_INFO', $path_info);

    // send this configuration array back to Environment::mock() to override its defaults for when // we start our app \Slim\Environment::mock( $env->getArrayCopy() );

    // proceed with the new environment set with the correct PATH_INFO $restapp = new \Slim\Slim();
    Not sure this is the proper way to change a property of the Environment, and it's not too intuitive. If there is any documentation of how to override Environment properties, please let me know. In the meantime I hope this helps others who may need to adjust how Slim expects the server path.
  26. 26 Posted by Julio on 18 Jul, 2017 03:34 AM

    Julio's Avatar

    This worked for me in AWS ubuntu 16
    Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All <-- original was None
    Require all granted

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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