Weblurk
Weblurk

Reputation: 6822

RewriteRule doesn't work when it should, why?

I want clean urls and my RewriteRule looks like this:

RewriteRule ^articles/([A-Z0-9-]+) /articles/index.php?slug=$1&%{QUERY_STRING} [PT,L]

which works fine but I also want lower case letters to be handled, and that's the parth which messes it all up and gives me an Internal Server Problem. If I change the above code to this...

RewriteRule ^articles/([A-Za-z0-9-]+) /articles/index.php?slug=$1&%{QUERY_STRING} [PT,L]

...then I get Internal Server Problem. The apache error log says:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

Anyone knows why I get this error when the only thing I do is to add handling of lower case letters?

Upvotes: 1

Views: 360

Answers (2)

Kaz
Kaz

Reputation: 58666

Also

You're using ...&%{QUERY_STRING}. If there is no query string you end up with ...& which could look like an empty superfluous parameter to whatever is processing the URL.

mod_rewrite has special handling of query strings so you don't need this. If you add the flag [QSA] it means that any query string material you added in the rewrite (denoted by a ?) will be recognized and combined with the existing query string.

Upvotes: 0

huelbois
huelbois

Reputation: 7022

The problem is your pattern: it doesn't have an ending symbol ($).

So when you call /articles/index.php..., it matches, because of /articles/index. Hence the redirect loop.

If you change your pattern like this:

RewriteRule ^articles/([A-Za-z0-9-]+)$ ...

It will work, because the dot character (.) won't match.

Upvotes: 2

Related Questions