How to remove index.php from slim framework URL

半城伤御伤魂 提交于 2019-11-29 14:58:03

问题


i'm trying to remove index.php form an URL:

this works

http://server/bw/index.php/test

this doesn't work

http://server/bw/test

i try to change .htaccess and watching on web i see that it should be like this:

RewriteEngine On
RewriteBase /bw/

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

i try editing it in this way:

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

or in this way:

RewriteEngine On

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

or in this way:

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

But when i try to access to http://server/bw/test it says me:

Not Found

The requested URL /bw/test was not found on this server.

Apache/2.2.15 (CentOS) Server at server Port 80

I check that inside my httpd.conf LoadModule rewrite_module modules/mod_rewrite.so is enable.. i don't know what to do now..

how can i solve? please help me!


回答1:


Try this, which used e.g. in WordPress

RewriteRule . index.php [L]

or this, which is used by e.g. Lavavel PHP Framework

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

You might also consider adding

RewriteCond %{REQUEST_FILENAME} !-d

before the RewriteRule to also exclude existing directories, not only existing files. But that's up to you.




回答2:


For me, I got things to work using this line from Dehalion's answer:

RewriteRule . index.php [L]

So the index.php (or any xyz.php) file is not seen in the request url

http://localhost/demo1/mycompany/hello/Jim

With the following caveats:

  1. You have this route defined:

    $app->get('/mycompany/hello/:name', doHello );

  2. The root element (for the route /mycompany/..) is also the name of the file.
    That is, the route exists in a file called "mycompany.php"

Yes, it's a bit of a hack ... but since I find apache config confusing/intimidating :) ... I figure this solution is stable enough to satisfy the requirements.




回答3:


In my case I updated AllowOverride All , then run sudo a2enmod rewrite to avoid Internal 500 error then restart Apache service apache2 restart



来源:https://stackoverflow.com/questions/14225283/how-to-remove-index-php-from-slim-framework-url

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