TheBarnacle
TheBarnacle

Reputation: 157

How to let mod_rewrite put non-alphanumeric characters in query string?

I am trying to add a redirect to .htaccess as follows:

RewriteRule ^resources/reports /resources?f[0]=field_resource_type%3Areports [R=301,L]

However, it is rewritten as resources?f%5b0%5d=field_resource_typeAreports which doesn't work. The [ and ] characters are encoded when they don't need to be, and the %3A seems to get lost.

If I copy-paste the exact replacement string into the browser then it has no problem, but I can't seem to add a RewriteRule to do it.

I have tried adding [B] and [NE] but they don't seem to make any difference.

Anyone had to do this before?

Upvotes: 2

Views: 229

Answers (1)

anubhava
anubhava

Reputation: 785186

You need to:

  1. Escape % in target otherwise %3 will be treated as back-reference
  2. Use NE (non encoded) flag

Use this rule:

RewriteRule ^resources/reports /resources?f[0]=field_resource_type\%3Areports [R=301,L,NE]

Test this after clearing your browser cache.

Upvotes: 2

Related Questions