.htaccess mod_rewrite用于嵌套文件夹结构

时间:2010-03-05 20:52:29

标签: .htaccess mod-rewrite url-rewriting nested subdirectory

我最近在网上发现了一篇关于此事的文章:

RewriteRule ^mock-up/([^/]+)/([^/]+) /mock-up/index.php?page=$1&section=$2 [NC]

现在只有让我疯狂的事情是,我是否希望能够拥有第二个目录。像:

RewriteRule ^mock-up/([^/]+)/([^/]+) /mock-up/index.php?page=$1&section=$2 [NC]
RewriteRule ^mock-up/([^/]+) /mock-up/index.php?page=$1 [NC]

但那打破了阿帕奇...那该怎么办?请帮助,我需要为我的客户seo,我不想为此制作单独的文件。

1 个答案:

答案 0 :(得分:1)

问题是mock-up/index.php也与mock-up/([^/]+)匹配。所以你需要直接排除目标:

RewriteRule ^mock-up/index\.php$ - [L]

或间接:

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

所以试试这个:

RewriteRule ^mock-up/index\.php$ - [L]
RewriteRule ^mock-up/([^/]+)/([^/]+)$ /mock-up/index.php?page=$1&section=$2 [NC]
RewriteRule ^mock-up/([^/]+)$ /mock-up/index.php?page=$1 [NC]