网页访问使用“this.php”;如果不满足上述条件


htaccess use "this.php" if the above conditions are not met

我有一个已经存在的php脚本,最近我想集成Slim框架。

我希望达到的是使用Slim路由作为最后的手段,如果我已经存在的重写条件没有得到满足,这意味着Slim也将处理404页面。

Slim framework .htaccess重写规则为:

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

,但是因为我已经有了index.php,所以我用this.php来实例化Slim,所以它应该是

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

问题来了,我已经有了预先存在的重写规则,我想保留,这里有一些重写规则:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
# Rewrite to www
RewriteCond %{HTTP_HOST} ^example.com [nc]
RewriteRule ^(.*)$ https://www.example.com/$1 [r=301,nc,l]
RewriteRule     ^category/([^/]*)/?$    category.php?console=$1 [L,QSA]
RewriteRule     ^category/([^/]*)/([^/]*)$  category.php?console=$1&page=$2 [L,QSA]
RewriteRule     ^category-amp/([^/]*)/([^/]*)$  category-amp.php?console=$1&page=$2 [L,QSA]
RewriteRule     ^games/([^/]*)/?$   games.php?console=$1 [L,QSA]
RewriteRule     ^forum^(.*)$ index.php 
RewriteRule     ^download.php?$ $1/new-page$2 [R=301,L]

因此,如果不满足上述任何模式,我希望他们使用this.php代替。

如果我加上

RewriteRule ^ this.php [QSA,L]

放到规则的底部。问题是,在使用它时,上面的每个规则都被忽略,导致所有查询都重定向到this.php,这将抛出Slim的404错误。我怎样才能使htaccess首先检查RewriteRule ^ this.php [QSA,L]上面设置的规则是否匹配,然后再将其最终传递给this.php ?

希望有人能帮忙

可以这样做,在底部保持slim规则:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
# Rewrite to www
RewriteCond %{HTTP_HOST} !^www'. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
RewriteRule ^download'.php$ /new-page [R=301,L]
RewriteRule ^category/([^/]*)/?$ category.php?console=$1 [L,QSA]
RewriteRule ^category/([^/]*)/([^/]*)$ category.php?console=$1&page=$2 [L,QSA]
RewriteRule ^category-amp/([^/]*)/([^/]*)$ category-amp.php?console=$1&page=$2 [L,QSA]
RewriteRule ^games/([^/]*)/?$ games.php?console=$1 [L,QSA]
RewriteRule ^forum index.php [L]
# slim rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ this.php [L]