.htaccess重写子页面

时间:2014-07-17 04:41:32

标签: php apache .htaccess mod-rewrite

我有当前的重写规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?page=$1 [L,QSA]

这对于http://www.example.com/something非常有用,但我也希望能够有子页面,即:http://www.example.com/something/something。我希望它采取以下形式:

index.php?page=$1&subpage=$2

index.php?page=something&subpage=$1

有人可以指出我正确的方向吗?

1 个答案:

答案 0 :(得分:5)

放手一搏:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&subpage=$2 [L,QSA]

你也可以在一个规则中制作这两个规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:([^/]+)|)(?:/([^/]+)|)/?$ index.php?page=$1&subpage=$2 [L,QSA]