我已经构建了一个Slim PHP应用程序并将其发布在我的网络服务器上.
仅当我通过index.php页面直接浏览时,路由才可用
例如example.com/index.php/login和/index.php/signup
两者都呈现预期的视图
但如果我省略index.php并浏览到`example.com/login’或’example.com/signup’,我会得到一个404
我的.htaccess文件与index.php位于同一目录中
public/
├── .htaccess
├── index.php
公用文件夹在apache中配置为DocumentRoot /var/www/example.com/public
我的.htaccess文件包含以下内容:
Options -MultiViews
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$/$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
有任何建议如何修复我的路由?
解决方法:
Slim建议对Apache使用这些规则. (htaccess的)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
Rembember您必须在Apache配置中将AllowOverride指令设置为“All”,并确保“/ public”是您的根虚拟目录.
标签:htaccess,php,apache
来源: https://codeday.me/bug/20190825/1713617.html