[英]changing url 301 redirection with htaccess or php
example.com/a=process&b=5&b_id=5
我该如何重定向到
example.com/a=process&b_id=5
因此,我可以删除所有传入网址的b = 5。 但是“ a”,“ b”和“ b_id”可变不是静态的。 我怎样才能做到这一点?
如果要进行内部重定向,请使用以下代码:
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等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.