重写使用Apache的mod_rewrite多个变量规则

问题描述:

我想知道我怎么可以重写 www.site.com?lang=lv&type=1&mode=2 WWW .site.com / LV / 1/2 使用Apache mod_rewrite的选项。

I would like to know how can I rewrite www.site.com?lang=lv&type=1&mode=2 into www.site.com/lv/1/2 using Apache mod_rewrite options.

您需要单独处理URI路径和查询。如果参数出现在非常相同的顺序,你可以这样做:

You need to handle the URI path and query separately. If the parameters appear in that very same order, you can do this:

RewriteCond %{QUERY_STRING} ^lang=([^&]+)&type=([^&]+)&mode=([^&]+)$
RewriteRule ^$ /%1/%2/%3? [L,R=301]

否则,你将需要把他们以正确的顺序使用这个规则之前,或采取每个参数在一个时间。

Otherwise you will need to put them in the right order before using this rule or take each parameter at a time.