为自定义PHP MVC框架重写多个.htaccess规则


multiple .htaccess rewrite rules for custom PHP MVC framework

我正在尝试构建custom PHP MVC framework,我想使用.htaccess重写执行以下操作

localhost/mvc/page1localhost/mvc/page1/对此
localhost/mvc/index/view/page1

localhost/mvc/bloglocalhost/mvc/blog/对此
localhost/mvc/blog/index

localhost/mvc/blog/blog1localhost/mvc/blog/blog1/对此
localhost/mvc/blog/view/blog1

这里indexblog是控制器

以下是我迄今为止尝试的

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=index/view/$1 [L,QSA] 

这会将localhost/mvc/page1重定向到localhost/mvc/index/view/page1

所以,基本上,我想对不同的控制器有不同的重写条件。所以,当我将添加一个新的控制器时,我将继续向htaccess文件添加条件。

这是一个代码隐藏重定向(URL不应更改),。CCD_ 16后面的所有内容都应该反映在GET $_GET['rt']参数中

如何做到这一点??

这样做:

RewriteEngine on
RewriteBase /mvc/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(blog)/?$ index.php?rt=$1/index [L,NC,QSA] 
RewriteRule ^(blog)/([^/]+)/?$ index.php?rt=$1/view/$2 [L,NC,QSA] 
RewriteRule ^(.+)$ index.php?rt=index/view/$1 [L,QSA]