在URL中省略index.php时,总是在Slim Framework中出现404错误

Ger*_*rre 7 php apache mod-rewrite slim

我按照这里的说明创建了一个测试hello world Slim应用程序.

当我拨打这个电话时,我收到404错误:

http://my_server/my_app/hello/John
Run Code Online (Sandbox Code Playgroud)

另一方面,当我拨打这个电话时,它会很棒,因为我收到了"Hello John"消息:

http://my_server/my_app/index.php/hello/John
Run Code Online (Sandbox Code Playgroud)

但是,当然,我不想在我的网址中使用index.php ......有什么不对的?

=======编辑=======

我忘了像这样创建.htaccess文件(在Slim Framework文档之后,和index.php在同一目录中):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
Run Code Online (Sandbox Code Playgroud)

现在我收到这个错误:

/physical_path_to_my_files/index.php was not found on this server
Run Code Online (Sandbox Code Playgroud)

Jon*_*Lin 16

如果您的htaccess文件位于您的/my_app目录中,请将规则更改为:

RewriteEngine On

RewriteBase /my_app/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
Run Code Online (Sandbox Code Playgroud)

如果它在您的文档根目录中,则需要附加路径:

RewriteRule ^ /my_app/index.php [QSA,L]
Run Code Online (Sandbox Code Playgroud)


Guy*_*Guy 5

也可以将.htaccess更改为以下内容:(我有类似的问题,这解决了我的问题):

的.htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
Run Code Online (Sandbox Code Playgroud)