htaccess 中的多个动态mod_rewrite


Multiple dynamic mod_rewrite in htaccess

我有一堆页面目前都是这样的:site.com/browse.php?cat=XXX 和一堆索引.php?p=QQQ

我怎样才能在 2 条规则中 site.com/XXX 和 site.com/QQQ?如何制定重写规则,以识别某些页面是否应重定向到浏览和某些页面以索引?

我尝试过使用多个规则来做到这一点,但它总是只接受第一条规则(例如,尝试重定向到浏览.php?cat=QQQ(。

谢谢

你需要一些方法来区分index.php和browse.php。这里有一个建议:

 site.com/QQQ
 site.com/browse/XXX

匹配和处理上述 URL 的重定向规则包括:

RewriteEngine On
# The following two lines prevent further rewriting on second pass
RewriteRule ^browse'.php$ - [L]
RewriteRule ^index'.php$ - [L]
# The following two lines cause mod_rewrite to do another pass
RewriteRule ^browse/(.+) browse.php?cat=$1 [L]
RewriteRule ^(.+) index.php?p=$1 [L]