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?
答案 0 :(得分:1)
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]