apache 拦截特定路由,重写路由-爱代码爱编程
由于使用yii的main.php配置路由会使得原本的路由后传参方式&key=value失效,变成/key/value,使得原本的框架有较大的改动量。现在使用.htaccess文件来拦截所需的特定路由
参考:
Apache的rewrite重写相关的参数详解说明(伪静态)
https://blog.csdn.net/keyunq/article/details/2536875
Apache重写规则解析
Apache 重写规则及参数详解,入门看这个就够了
实现:
RewriteEngine on
# unit/test => index.php?r=unit/test&test=unit
RewriteRule ^(.*)/test$ index.php?r=unit/test&test=$1 [NC,L]
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
条件要放在默认的index.php上面,不让会先执行RewriteRule . index.php
导致$1变成index.php