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

wrong routing

drivefast's Avatar


14 Mar, 2012 10:42 PM

here is a slight modification of the "hello world" application.

$app = new Slim();

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

$app->get("/", function() use ($app) {
    echo "Hello, nobody<br>";
    echo "param=" . $app->request()->get('param') . "<br>";
    echo "root: '" . $app->request()->getRootUri() . "'<br>";
    echo "resource: '" . $app->request()->getResourceUri() . "'<br>";


now for an url like

i get the response:

Hello, nobody
root: '/hello/there'
resource: '/'

so it's pretty clear that my root path is incorrectly determined, and thus the resource is misinterpreted. instead of having the first app->get() function called, the second one gets called, and the printout of the request internal variables indicate the source of the problem.

as something that i consider related, i must say that initially i had quite some trouble with the contents of the .htaccess file. i moved the mod_rewrite configuration in the httpd.conf, like this:

<VirtualHost x.x.x.x:80>
    DocumentRoot /path/to/rest/
    RewriteEngine On
    RewriteLog "/tmp/rw.log"
    RewriteLogLevel 9
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php [QSA,L]

note that i am running the slim framework in a subdomain. also, i had to change the rewrite rule to /index.php, as opposed to just index.php - if this matters in any way. OS is centos 6, http server is apache, php is 5.3.3.

anybody has a clue on what could i have screwed up with my settings? really appreciated.

  1. Support Staff 1 Posted by Josh Lockhart on 25 Mar, 2012 03:22 PM

    Josh Lockhart's Avatar

    In your example, the first route's pattern must have a leading forward slash; currently, it does not. It should look like:

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

    Let me know if this resolves the issue.

  2. Josh Lockhart closed this discussion on 12 Feb, 2021 07:50 PM.

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