【发布时间】:2015-08-09 18:40:12
【问题描述】:
我有以下代码:
RewriteEngine On
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^category/(.*)$ searchPage.php?crs_category=$1 [NC,QSA]
RewriteRule ^ index.php [QSA,L]
现在 Slim 框架的工作方式是将所有请求重定向到 index.php,其中 index.php 将请求的路径路由到其渲染页面。
因此,输入category/business 不会重写searchPage.php?crs_category=business 的url,而是重定向到index.php,因为没有定义要路由的路径category/:name,Slim Framework 将抛出一个找不到页面。
我的问题是解决这种情况,我希望除category/NAME 之外的所有请求都重定向到index.php。
如果有人键入 searchPage.php?crs_category=business 以将该 URL 重写为类别/业务,最好是 301 状态代码,我也将不胜感激。
【问题讨论】:
标签: php apache .htaccess mod-rewrite slim