Reputation: 389
I have this case where the rewrite only works without www and https, this is .htaccess
:
RewriteRule ^en/(.*)/1348-duracell-32-aaa-pack.html$ /$1/3016-duracell-32-aaa-pack.html [R=301,NC,L]
this URL works and redirects:
http://example.com/en/car-accessories/1348-duracell-32-aaa-pack.html
this one doesn't:
https://www.example.com/en/car-accessories/1348-duracell-32-aaa-pack.html
any ideas? I spent a good few hours on this without any solution, not sure what's wrong. The rule is on top of the .htaccess
file.
Any help would be greatly appreciated.
Upvotes: 0
Views: 46
Reputation: 1836
What do you mean by doesn't work ? Is the 2nd URL even redirecting ? If you are on a Linux platform you might want to try curl -L --head <url>
, then you can see if redirections or taking place (or a redirection loop). Actually curl
is a better way to test your rules, because your browser cache could be playing tricks on you.
Note that $1
is the first captured group from your regular expression. So you should add the host you want to redirect to ie:
RewriteRule ^en/(.*)/1348-duracell-32-aaa-pack.html$ https://example.com/$1/3016-duracell-32-aaa-pack.html [R=301,NC,L]
Otherwise the browser is very likely going to keep using the current host name. If you don't provide a full URL, then it has to make up for the missing bits.
But if all you want is remove /en/
from the URL, then you could write a simpler and more straightforward rule.
Upvotes: 1