htaccess url 用 RegEx 重写
htaccess url rewrite with RegEx
我想重定向一些 url,但遇到了一些问题。 url 像:
/sample?back=my-account
/sample?back=history
/sample?back=addresses
并且需要重定向到
/sample
我最后一次尝试是这样的(但没有成功):
RewriteCond %{QUERY_STRING} ^?back=history$
RewriteRule ^sample$ /sample [R=301,L]
您可以使用此修复程序:
RewriteCond %{QUERY_STRING} ^back=
RewriteRule ^sample$ /sample? [R=301,L]
这会将 http://example.com/sample?back=my-account
重定向到 http://example.com/sample
。
显然,您的条件不满足,因为查询字符串以 back
开头,要删除查询字符串,您需要将 ?
添加到替换字符串的末尾。
Apache Module mod_rewrite documentation:
When you want to erase an existing query string, end the substitution
string with just a question mark.
我想重定向一些 url,但遇到了一些问题。 url 像:
/sample?back=my-account
/sample?back=history
/sample?back=addresses
并且需要重定向到
/sample
我最后一次尝试是这样的(但没有成功):
RewriteCond %{QUERY_STRING} ^?back=history$
RewriteRule ^sample$ /sample [R=301,L]
您可以使用此修复程序:
RewriteCond %{QUERY_STRING} ^back=
RewriteRule ^sample$ /sample? [R=301,L]
这会将 http://example.com/sample?back=my-account
重定向到 http://example.com/sample
。
显然,您的条件不满足,因为查询字符串以 back
开头,要删除查询字符串,您需要将 ?
添加到替换字符串的末尾。
Apache Module mod_rewrite documentation:
When you want to erase an existing query string, end the substitution string with just a question mark.