将URL重写为查询字符串

时间:2017-04-14 06:24:28

标签: .htaccess url-rewriting

我知道如何反向重写并处理查询字符串,但我需要根据标记或类别以小写形式创建一个查询字符串参数。因此,我可以在我的页面中将查询字符串用作搜索参数:

e.g。

news/tag/Shipping/ ==> http://www.example.com/news/?tag=shipping
news/category/Other/ ==> http://www.example.com/news/?category=other

尝试

RewriteEngine On
RewriteRule ^news/([^/]*)$ /?tag=$1 [L]

谢谢。

1 个答案:

答案 0 :(得分:1)

您需要2个重写规则。

RewriteEngine On

RewriteRule ^news/([\w-]+)/?$ news/?tag=$1 [L,QSA,NC]

RewriteRule ^news/([\w-]+)/([\w-]+)/?$ news/?$1=$2 [L,QSA,NC]
相关问题