瘦PHP路由不起作用


Slim PHP routes not working

我已经构建了一个Slim PHP应用程序,并将其发布在我的Web服务器上。

只有当我直接通过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 中,public文件夹被配置为DocumentRoot /var/www/example.com/public

我的.htaccess文件包含以下内容:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>
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]
</IfModule>

有什么建议如何修复我的路由吗?

Slim建议在Apache中使用这些规则。(.htaccess)

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

Rembember您必须在Apache配置中将AllowOverride指令设置为"All",并确保"/public"是您的根虚拟目录。