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

发布于 2024-08-23 19:43:12 字数 408 浏览 5 评论 0原文

我最近在网上发现一篇文章告诉我这一点:

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]

但这破坏了阿帕奇......那么该怎么办?请帮忙,我需要为我的客户进行搜索引擎优化,我不想为此制作单独的文件。

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

RewriteRule ^mock-up/([^/]+)/([^/]+) /mock-up/index.php?page=$1§ion=$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 ^mock-up/([^/]+)/([^/]+) /mock-up/index.php?page=$1§ion=$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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

許願樹丅啲祈禱 2024-08-30 19:43:12

问题是 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§ion=$2 [NC]
RewriteRule ^mock-up/([^/]+)$ /mock-up/index.php?page=$1 [NC]

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§ion=$2 [NC]
RewriteRule ^mock-up/([^/]+)$ /mock-up/index.php?page=$1 [NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文