htAccess - 如果查询字符串与特定单词匹配,则替换路径


htaccess - replace path if query string match certain word

我有以下重写规则

RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$   articles.php?t=$1&p=$2    [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([0-9-]+)/?$   articles.php?t=$1&p=$2&id=$3    [NC,L]

我的问题是,如果p的值community我希望它重定向到社区.php并保留查询字符串。

因此,网址将变为community.php?t=$1&p=$2&id=$3community.php?t=$1&p=$2

谢谢

在现有规则之前,您可以有 2 个这样的附加规则:

RewriteCond %{REQUEST_URI} ^/[a-z0-9-]+/community/ [NC]
RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/?$ community.php?t=$1&p=$2 [L,QSA,NC]
RewriteCond %{REQUEST_URI} ^/[a-z0-9-]+/community/ [NC]
RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/([0-9-]+)/?$ community.php?t=$1&p=$2&id=$3 [L,QSA,NC]