我正在使用php中的自定义MVC模式,其中包含以下url实现
www.test.com/module/controller/action?params
通过php我正在拆分网址以查找模块,控制器,操作。效果很好。
我有情况显示像www.test.com/sale
这样的网址。以前我的网址是www.test.com?id=1
,其中id是类别sale
,它将通过php脚本调用相应的模块,控制器和操作。
我正在使用以下htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
我的重写更改不应该影响现有的流量,我需要专门应用重写条件,当我点击网址www.test.com/sale
它应该像我可以用于任何其他类别的那样明智地调用www.test.com?id=1
。
答案 0 :(得分:1)
您可以这样做:
RewriteEngine on
RewriteRule ^sale/?$ index.php?id=1 [QSA,NC,L]
RewriteRule ^purchase/?$ index.php?id=2 [QSA,NC,L]
RewriteRule ^admin/?$ index.php?id=3 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]