I try to redirect domain.tld/?cur=usd
to domain.tld
(there are many curencies, this is only example of one currency - we do not use anymore this solution).
I need to redirect only home with parameter to home without parameter. The other urls worked for me, I'm just having trouble getting work with that one.
I try to search and use online generators but none of the solutions work. Here is what I am trying:
RewriteCond %{QUERY_STRING} (^|&)cur\=(.*)($|&)
RewriteRule ^$ /? [L,R=301]
// update before this rule I have only
#bof redirects
RewriteEngine enabled
...and then there are redirects for other URLs, but I tested this rule separately first and the result was the same...
It not redirect me. Thanks for the help and maybe an explanation of what I'm doing wrong.
CodePudding user response:
RewriteCond %{QUERY_STRING} (^|&)cur\=(.*)($|&) RewriteRule ^$ /? [L,R=301]
As mentioned in comments, this should already do as you require, providing there are no conflicts with other directives in the .htaccess
file.
However, the regex in the preceding condition is excessively verbose for what you are trying to achieve (ie. just testing for the presence of the cur
URL parameter).
If you simply want to check for the cur
URL parameter anywhere in the query string then the regex (^|&)cur=
would suffice (and is more efficient). No need to backslash-escape the literal =
. And if the URL parameter always appears at the start of the query string then just use ^cur=
.
CodePudding user response:
I found the problem - it was something with the hosting, after a reboot everything started working as expected.
So I can confirm that this rule is fine.
Sorry for question.