Search code examples
regexmod-rewrite

RewriteCond doesn't match, while literally it should


The goal is to make redirect from

/Swiss+Military/something..

to

/Swiss+Military+Hanowa/something..

I've tried:

RewriteCond %{REQUEST_URI} /Swiss+Military/(.*)
RewriteRule .* /Swiss+Military+Hanowa/%1 [R=301,L]

Rewrite log at level 9 reveals the following:

RewriteCond: input='/Swiss+Military/' pattern='/Swiss+Military/(.*)' => not-matched

I can't figure out why it is not matched.. Any ideas?

SOLVED - need to escape + signs at the pattern (how didn't I recall that myself)

edit There is even better solution for this case (which I didn't put at the beginning because it didn't work - of the same reason as the posted one) - just a single RewriteRule:

RewriteRule /Swiss\+Military/ /Swiss+Military+Hanowa/ [R=301,L]

Solution

  • RewriteCond uses Perl syntax for the pattern. That means the the '+' in your pattern means "match 1 or more" (of the previous character). Try escaping the '+' in your pattern by putting a slash in front of it like this: '\+'.