views:

26

answers:

1

this rewriterule only rewrite level.php and when try localhost/a/b/115-aaa.html send all requests to level.php but localhost/a/b/ is work

why ?

RewriteEngine On
RewriteRule ^(.*)\/(.*)-(.*).html$ page.php?page=$1&a=$2&b=$3 [QSA]
RewriteRule ^(.*)$ level.php?q=$1 [QSA]
A: 

If your first rule matches it goes to page.php?page=foo&a=bar&b=123 . This will match a second time against your rules and the second rule match. You can avoid this by adding following lines to your .htacces file.

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)\/([a-zA-Z0-9]+)\/([0-9]+)\-([a-zA-Z0-9]+)\.html$ page.php?page=$1&a=$2&b=$3 [L]
#Prevent the last rule to be applied to page.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ level.php?q=$1 [L]
DrDol