假设我有带有如下查询字符串参数的 URL:
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
上面的 url 值是动态的。
最佳答案
类似这样的事情:
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]
记住,检查所有可能的陈述;)
关于apache - 重写查询 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7755962/