hengecyche
hengecyche

Reputation: 409

htaccess rule giving 500 server error

RewriteEngine On
RewriteRule ^([^/]*)$ /?menu=$1 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ \?menu=$1&cat=$2&product=$3 [L]

Tests:

http://localhost/about-us >> 500 server error with first rule present || 404 not found with only second rule
http://localhost/product/cat1/pro1 >>>works only with second rule || with first rule present 500 error
(only localhost/product has sub queries)

I am relatively beginner on apache rewrite. If i remove the first rule the code works though even if i remove the second one it still gives me 500 server error. It seems like the first rule is clashing with second one giving the error. how can i solve this?

Upvotes: 1

Views: 42

Answers (1)

anubhava
anubhava

Reputation: 786136

You should avoid rewriting for all files/directories otherwise your rules can loop and causes 500 error eventually:

RewriteEngine On

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/?$ ?menu=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ ?menu=$1&cat=$2&product=$3 [L,QSA]

Upvotes: 1

Related Questions