Mod rewrite 如何避免重复/类似的mod_重写规则?
我有许多URI,如下所示:Mod rewrite 如何避免重复/类似的mod_重写规则?,mod-rewrite,Mod Rewrite,我有许多URI,如下所示: (关于) (帮助) (联系人) 有没有办法避免编写明确但类似的重写规则 示例 RewriteRule ^contact$ index.php?route=information/information&information_id=2 [NC,L] # About RewriteRule ^help$ index.php?route=information/information&information_id
RewriteRule ^contact$ index.php?route=information/information&information_id=2 [NC,L] # About
RewriteRule ^help$ index.php?route=information/information&information_id=4 [NC,L] # Help
很多可能性。最简单的可能是这样的:
^(.*)$ index.php?route=information/information&information_id=$1
然后处理index.php
中的信息\u id
字符串。确保它只允许可接受的值,而不允许其他任何值
或者在mod_rewrite
级别进行更严格的限制:
^(contact|help|foo)$ index.php?route=information/information&information_id=$1
如果要重写的页面不止一部分,关键是在索引页面中有一个简单的重写规则与逻辑相结合,以便根据请求的URL提供正确的内容
请查看.htaccess和index.php中支持url重写的流行CMS,您将找到您想要的内容。谢谢。当您在
index.php
中说handle
字符串时,您的意思是什么?