Trying to implement a simple .htaccess redirect none of these work, any idea how to fix ?
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.
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.
Besides this, keep in mind that the first argument of RewriteRule
is a regex. 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 ?
behind the rewrite part.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.