重写查询URL

时间:2011-10-13 14:46:54

标签: apache mod-rewrite

假设我的网址包含以下查询字符串参数:

index.php?lag=en&name=About Us&itemid=60
index.php?host=consumer&lag=en&name=About Us&itemid=64

使用mod_rewrite,我该如何重定向它们?

en_About Us_60.php
consumer/en_About Us_64.php

在上面的网址中,值是动态的。

1 个答案:

答案 0 :(得分:0)

这样的事情:

RewriteEngine on 
RewriteCond %{QUERY_STRING} host=(.*)&lag=(.*)&name=(.*)&itemid=(.*)
RewriteRule ^index.php(.*)$ /%1/%2_%3_%4 [QSA]

RewriteCond %{QUERY_STRING} lag=(.*)&name=(.*)&itemid=(.*)
RewriteRule ^index.php(.*)$ /%1_%2_%3 [QSA]

请记住,检查所有可能的陈述;)