Wamp, SlimPHP and Htaccess

牧云@^-^@ 提交于 2019-12-12 21:07:11

问题


I am having issues with getting Slim to recognize the following:

$app = new \Slim\Slim();

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

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

$app->run();

It will see the first route just fine, how ever the second one returns a

Not Found

The requested URL /image-uploader/gg was not found on this server.

Which lead me to believe I didnt have the re-write mod enabled in wamp. So I enabled it and set AllowOverride to All

I then restarted wamp and visited localhost/image-uploader/ and I get Hello, how ever visiting the second route gives the error above.

Why? My htaccess is as such:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule index.php [L]
</IfModule>

回答1:


Since your project is not in root folder but in image-uploader folder, your path is not correct.

You can change RewriteBase as follow (assuming your htaccess is in image-uploader folder)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /image-uploader/

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>

Now, it should be working as expected. Actually, i don't know much more about SlimPHP but it looks like it's fine



来源:https://stackoverflow.com/questions/29953704/wamp-slimphp-and-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!