开发者

.htaccess mod_rewrite for nested folder structuring

I recently found an article online that told me about this:

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

Only thing that is driving me crazy right now is if I want to be able to have the 2nd directory or not. Like:

RewriteRule 开发者_JAVA技巧^mock-up/([^/]+)/([^/]+) /mock-up/index.php?page=$1&section=$2 [NC]
RewriteRule ^mock-up/([^/]+) /mock-up/index.php?page=$1 [NC]

But that's breaking apache... so what to do? Please help, I need to seo for my client and I would prefer not to have to make individual files for this.


The problem is that mock-up/index.php is also matched by mock-up/([^/]+). So you need to exclude the target, either directly:

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

Or indirectly:

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

So try this:

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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜