How to remove index.php from slim framework URL

前端 未结 3 1594
南笙
南笙 2020-12-16 06:30

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

this works

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

this doesn\'t work

http://s         


        
相关标签:
3条回答
  • 2020-12-16 07:19

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

    0 讨论(0)
  • 2020-12-16 07:30

    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.

    0 讨论(0)
  • 2020-12-16 07:30

    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.

    0 讨论(0)
提交回复
热议问题