[SOLVED] Slim framework cannot make routing work

In Slim framework, cannot make routing work well as in the example provided on the site:

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

Only / will work. All the other URLs like /hello/Bob will throw a 404.
Solution is to setup apache correctly.
1. In the same folder with your index.php create a .htaccess file:

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

2. In the httpd.conf of apache server put this at the end. Change as needed – mysite.com should be replaced with something like slim.localhost, also documentRoot and Directory should point to the correct path of apache:

<VirtualHost *:80>
    ServerAdmin me@mysite.com
    DocumentRoot "/path/www.mysite.com/public_html"
    ServerName mysite.com
    ServerAlias www.mysite.com

    #ErrorLog "logs/mysite.com-error.log"
    #CustomLog "logs/mysite.com-access.log" combined

    <Directory "/path/www.mysite.com/public_html">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

3. Restart apache

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s