Question

I am trying to rewrite any urls that end on a sequence of numbers and capitalized letters. Unfortunately I have only been partially successful. This is my .htaccess file:

RewriteEngine On
RewriteRule [A-Z0-9]+$ index.php?r=wizard/index&key=$1 [L]

For some reason, this only works for my urls that end on

key=QO106A654O65NN6828N

If the equal sign is missing from the url like this

keyQO106A654O65NN6828N

the url is not matched. I don't understand why that equal sign is significant since it's not even part of the regex. What could be causing this behavior?

As requested some example urls that don't work unless an '=' sign is inserted as described above:

/index.php?r=wizard/index&id&key4C2918IFIY3U4APKOI1
/index.php?r=wizard/index&id\xEF\xBF\xBD&keyQO106A654O65NN6828N
Was it helpful?

Solution

You cannot match QUERY_STRING using rewrite rule.

Have your rule like this:

RewriteEngine On

RewriteCond %{QUERY_STRING} (?:^|&)key([A-Z0-9]+)$
RewriteRule ^(index\.php)?$ $1?r=wizard/index&key=%1 [L,NE]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top