我按照这里的说明创建了一个测试hello-world Slim应用程序。
当我打这个电话时,我得到一个404错误:
http://my_server/my_app/hello/John
另一方面,当我打这个电话时,收到一条"你好,约翰"的消息,效果很好:
http://my_server/my_app/index.php/hello/John
但是,当然,我不想在我的URL中使用index.php。。。可能出了什么问题?
======编辑======
我忘了创建这样的.htaccess文件(遵循Slim Framework文档,位于和index.php相同的目录中):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
现在我得到这个错误:
/physical_path_to_my_files/index.php was not found on this server
如果htaccess文件在/my_app
目录中,请将规则更改为:
RewriteEngine On
RewriteBase /my_app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
如果它在你的文档根目录中,你需要附加路径:
RewriteRule ^ /my_app/index.php [QSA,L]
还可以将.htaccess更改为以下内容:(我遇到了类似的问题,这为我解决了它):
.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
如果Jon Lin解决方案不起作用,则表示.htaccess文件不起作用。你可以验证我是否添加了一条类似的垃圾线
RewriteEngine On
RewriteBase /loop/v1/
This is garbage line
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
如果.htaccess运行良好,这将产生503错误,否则将不会出现任何错误。
如果没有得到任何错误,请将apache conf文件或Httpd.conf 的Allow none更改为Allow all
此资源解释了在Ubuntu上使用slim所需的所有配置(它帮助我解决了404问题):
总之,有两件事需要配置:
- 激活mod_rewrite
a2enmod rewrite
- 修改Apache配置文件(将
AllowOverride None
更改为AllowOverride All
对于文档根)
不要忘记在更改后重新启动apache2:service apache2 restart
如何在Ubuntu 14.04 上安装和配置Slim Framework