tom84
tom84

Reputation: 401

Redirect Match with excluding URLs doesnt work

I use a RedirectMatch rule which should exclude the following two URLs:

I use this rule with regex, but I get a 500 Internal Server Error:

RedirectMatch 301 /citycards/citycards-locations/muenchen/((?!citycards/citycards-locations/munche‌​n/citycards-trachtenvogl-reichenbachst‌​r-47-munchen|citycards/citycards-location‌​s/munchen/citycards-4-you-munchen-hirtenstrasse-18‌​-munchen ).+)$ /citycards/citycards-locations/muenchen/$1

Any ideas why it doesn't work?

Upvotes: 2

Views: 140

Answers (2)

hjpotter92
hjpotter92

Reputation: 80629

Your rule currently is: (broken down to multiple lines for better display/understanding):

RedirectMatch
301
/citycards/citycards-locations/muenchen/((?!citycards/citycards-locations/munche‌​n/citycards-trachtenvogl-reichenbachst‌​r-47-munchen|citycards/citycards-location‌​s/munchen/citycards-4-you-munchen-hirtenstrasse-18‌​-munchen ).+)$
/citycards/citycards-locations/muenchen/$1

Basically, your regex says that:

  • match /citycards/citycards-locations/muenchen/
  • which is not followed by either of the following

    1. citycards/citycards-locations/munche‌​n/citycards-trachtenvogl-reichenbachst‌​r-47-munchen,
    2. citycards/citycards-location‌​s/munchen/citycards-4-you-munchen-hirtenstrasse-18‌​-munchen (it has a space after 18‌​-munchen)
  • match everything until the end of URI

and redirect the matched URI to: /citycards/citycards-locations/muenchen/$1 which is basically the same URL that was matched against.

I see 2 issues.

  1. If the blank space in your negative lookahead is not considered as a part of the pattern, you are essentially passing 4 arguments to RedirectMatch directive, leading to status 500 error
  2. If the pattern is getting parsed correctly, you have an infinite redirection loop.

Upvotes: 3

MrWhite
MrWhite

Reputation: 45829

/citycards-4-you-munchen-hirtenstrasse-18‌​-munchen ).+)$

You have an unescaped space near the end of your RewriteRule pattern. This will certainly cause a 500 error since the space is a delimiter and the arguments will not match up (invalid flags).

It looks like this is a typo and should simply be removed?

Upvotes: 0

Related Questions