Getting A 500 Internal Server Error in my URL Rewrite Rules

Viewed 1873

If have the following possible urls:

http://stackoverflow.com/categories/
http://stackoverflow.com/categories/category-type
http://stackoverflow.com/categories/category-type/category
http://stackoverflow.com/categories/category-type/category/sub-category

which I want to rewrite to

http://stackoverflow.com/categories/
http://stackoverflow.com/categories/?category-type=category-type
http://stackoverflow.com/categories/?category-type=category-type&category=category
http://stackoverflow.com/categories/?category-type=category-type&category=category&sub-category=sub-category

And here are my rewrite rules:

RewriteRule ^categories/([^/]*)/([^/]*)/([^/]+)(/)?$ /categories/?category-type=$1&category=$2&sub-category=$3 [NC,L]

RewriteRule ^categories/([^/]*)/([^/]+)(/)?$ /categories/?category-category=$1&category-=$2 [NC,L]

RewriteRule ^categories/([^?][^/]*)(/)?$ /categories/?category-type=$1 [NC,L]

The last rule is causing a 500 Internal Server Error. What is causing this?

6 Answers

The last rule is causing a 500 Internal Server Error. What is causing this?

It's a loop. Your rule's target, /categories/ matches the pattern ^categories/([^?][^/]*)(/)?$, since all that stuff after the / is optional. Try making the * a + to force at least 1 character there:

RewriteRule ^categories/([^?][^/]+)(/)?$ /categories/?category-type=$1 [NC,L]
Related