Mobile app version of vmapp.org
Login or Join
Jamie184

: To redirect a request for /something%26else (or /something&else, since the ampersand does not need to be escaped in the URL-path) to /something%2526else (ie. /something%26else when decoded)

@Jamie184

To redirect a request for /something%26else (or /something&else, since the ampersand does not need to be escaped in the URL-path) to /something%2526else (ie. /something%26else when decoded) then you could do something like:

RewriteRule ^(something)&(else)$ /%26 [R,L]


The RewriteRule pattern matches against the %-decoded URL-path (ie. &, not %26). So you should simply specify & (ampersand) literally.

The % (percent) in the RewriteRule substitution needs to be backslash escaped in order to represent a literal %, otherwise it's going to be seen as a backreference to the last matched CondPattern, and there isn't any, so %2 would otherwise becomes an empty string!

Without the NE (noescape) flag, mod_rewrite will automatically encode the substitution URL, which is actually what we want in this instance: %26 gets encoded as %2526. (Which, when decoded, is seen as a literal %26.)

Alternatively, you could use the NE flag (that danlefree mentions) and then manually encode the substitution:

RewriteRule ^(something)&(else)$ /%2526 [R,L,NE]

10% popularity Vote Up Vote Down


Login to follow query

More posts by @Jamie184

0 Comments

Sorted by latest first Latest Oldest Best

Back to top | Use Dark Theme