.htaccess mod_rewrite:将查询字符串重写为路径 [英] .htaccess mod_rewrite: rewriting querystring to path
本文介绍了.htaccess mod_rewrite:将查询字符串重写为路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用重写来更改:
How could I use a rewrite to change:
/?tag=foo
致:
/tag/foo
我试过了:
RewriteCond %{QUERY_STRING} ^tag=(.+)$
RewriteRule ^(.*)$ http://www.example.com/tag/$1 [L]
但是没有用.
推荐答案
为了避免递归,你应该检查 请求行 代替,因为 %{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屋!
查看全文