example.com/a=process&b=5&b_id=5
如何将其重定向到
example.com/a=process&b_id=5
所以我可以删除所有传入网址的b = 5。但是“a”,“b”和“b_id”可以变化而不是静止的。我怎么能这样做?
答案 0 :(得分:0)
如果要进行内部重定向,请使用以下代码:
RewriteEngine On
# The query variable b is comming first.
RewriteCond %{QUERY_STRING} ^b=[0-9]*&(.*)$
RewriteRule ^(.*)$ %2?%1 [L,NS]
# The query variable b is comming in middle.
RewriteCond %{QUERY_STRING} ^(.*)&b=[0-9]*&(.*)$
RewriteRule ^(.*)$ %3?%1&%2 [L,NS]
# The query variable b is comming last.
RewriteCond %{QUERY_STRING} ^(.*)&b=[0-9]*$
RewriteRule ^(.*)$ %2?%1 [L,NS]
然后只需打印print_r($_GET);
查询变量b
将不在数组中。
如果要进行外部重定向,请使用以下代码:
RewriteEngine On
# The query variable b is comming first.
RewriteCond %{QUERY_STRING} ^b=[0-9]*&(.*)$
RewriteRule ^.*$ %{REQUEST_URI}?%1 [R,L,NS]
# The query variable b is comming in middle.
RewriteCond %{QUERY_STRING} ^(.*)&b=[0-9]*&(.*)$
RewriteRule ^.*$ %{REQUEST_URI}?%1&%2 [R,L,NS]
# The query variable b is comming last.
RewriteCond %{QUERY_STRING} ^(.*)&b=[0-9]*$
RewriteRule ^.*$ %{REQUEST_URI}?%1 [R,L,NS]
查看http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html以了解R,L,NS等。