我已经有一个现有的php脚本,最近我想集成Slim框架。
我希望达到的是使用Slim路由作为最后的手段,如果我已经存在的所有重写条件都不满足,这意味着Slim也将处理404页。
超薄框架.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错误。在最终传递给this.php之前,如何让htaccess先检查上面设置的RewriteRule ^ this.php [QSA,L]规则是否匹配
希望有人能帮上忙。
发布于 2016-09-09 06:16:33
通过在底部保持纤细的规则来这样做:
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]https://stackoverflow.com/questions/39400955
复制相似问题