开发者

.htaccess mod_rewrite for nested folder structuring

开发者 https://www.devze.com 2022-12-22 05:36 出处:网络
I recently found an article online that told me about this: RewriteRule ^mock-up/([^/]+)/([^/]+) /mock-up/index.php?page=$1&section=$2 [NC]

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

精彩评论

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

关注公众号