user1228140
user1228140

Reputation: 11

Allow Ampersand in mod_rewrite

I am trying to allow '&' in my mod_rewrite. at the moment i am using

RewriteRule ^([-a-zA-Z0-9_'_-]+)$

I tried adding:

RewriteRule ^([-a-zA-Z0-9_'_-_&]+)$

to allow ampersand, yet i know it is most likey wrong. can anyone direct me in the right direction for the correct regex layout.

Upvotes: 1

Views: 415

Answers (1)

Anthony Hatzopoulos
Anthony Hatzopoulos

Reputation: 10537

You also must escape the hyphen because it indicates range for matching inside square brackets (it doesn't fail because you included it last but in other cases it would have like in OP).

Proper escaping of hyphen: ^([a-zA-Z0-9'&_\-]+)$

this would fail: ^([a-zA-Z0-9'_-&]+)$

this would not: ^([a-zA-Z0-9'_\-&]+)$

(i would have commented but my rep is not high enough)

Upvotes: 1

Related Questions