[英]simple htaccess RewriteRule or redirect doesnt work properly
Trying to implement a simple .htaccess redirect none of these work, any idea how to fix ? 试图实现一个简单的.htaccess重定向,这些工作都没有,怎么解决?
RewriteRule ^/en/?productsublayout=products_horizon http://www.example.com/en/ [R=302,L]
Redirect 301 /en/?productsublayout=products_horizon http://www.example.com/en/
Read the documentation of mod_rewrite , as your code has two common problems, both which already have been addressed in the documenation. 阅读mod_rewrite的文档 ,因为您的代码有两个常见问题, 文档中已经解决了这两个常见问题。
Per-directory Rewrites 每目录重写
[..] [..]
- The removed prefix always ends with a slash, meaning the matching occurs against a string which never has a leading slash. 删除的前缀始终以斜杠结尾,这意味着匹配是针对从未有前导斜杠的字符串进行的。 Therefore, a Pattern with
^/
never matches in per-directory context. 因此,带有^/
的模式在每个目录上下文中都不会匹配。
and 和
If you wish to match against the hostname, port, or query string, use a RewriteCond with the
%{HTTP_HOST}
,%{SERVER_PORT}
, or%{QUERY_STRING}
variables respectively. 如果希望与主机名,端口或查询字符串匹配,请分别将RewriteCond与%{HTTP_HOST}
,%{SERVER_PORT}
或%{QUERY_STRING}
变量一起使用。
Besides this, keep in mind that the first argument of RewriteRule
is a regex. 除此之外,请记住, RewriteRule
的第一个参数是正则表达式。 The ?
?
character has a special meaning in a regex. 字符在正则表达式中具有特殊含义。
You have to correct it like this: 您必须像这样纠正它:
RewriteCond %{QUERY_STRING} ^productsublayout=products_horizon$
RewriteRule ^en/$ /en/? [R=302,L]
Alternatively, if you have a recent version of Apache, use the QSD
flag instead of a trailing ?
另外,如果您使用的是Apache的最新版本,请使用QSD
标志而不是尾随的?
behind the rewrite part. 在重写部分的后面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.