的.htaccess mod_rewrite的:重写查询字符串为路径 [英] .htaccess mod_rewrite: rewriting querystring to path
本文介绍了的.htaccess mod_rewrite的:重写查询字符串为路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么会用一个重写改变:
How could I use a rewrite to change:
/?标记=富
要:
/标签/富
我想:
RewriteCond %{QUERY_STRING} ^tag=(.+)$
RewriteRule ^(.*)$ http://www.example.com/tag/$1 [L]
但没有奏效。
But it did not work.
推荐答案
要避免递归,你应该检查的请求线,而不是的如%{QUERY_STRING}
可能已经被另一个规则已经改变的查询字符串:
To avoid recursion, you should check the request line instead as the query string in %{QUERY_STRING}
may already have been changed by another rule:
RewriteCond %{THE_REQUEST} ^GET\ /\?(([^&\s]*&)*)tag=([^&\s]+)&?([^\s]*)
RewriteRule ^(.*)$ /tag/%3?%1%4 [L,R=301]
然后你可以重写请求回内部没有矛盾:
Then you can rewrite that requests back internally without conflicts:
RewriteRule ^tag/(.*) index.php?tag=$1 [L]
这篇关于的.htaccess mod_rewrite的:重写查询字符串为路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文