【问题标题】:.htaccess rewrite rule not working for subfolder.htaccess 重写规则不适用于子文件夹
【发布时间】:2021-09-07 07:28:08
【问题描述】:

我的重写规则有问题。 我有下面的重写代码

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^subcategory/([0-9a-zA-Z_-]+) child-category.php?cat=$1 [NC,L,QSA]
RewriteRule ^([^\.]+?)/?$ $1.php [NC,L]

效果很好,但是当我在子文件夹 doctor 中添加 child-category.php 并尝试访问该文件时它不起作用。

http://localhost:8888/community/doctor/subcategory/health -> 不起作用 http://localhost:8888/community/subcategory/health -> 工作正常。

它应该在子文件夹中也可以工作,任何人都可以看到任何明显的为什么它不工作吗?

【问题讨论】:

  • ^ 在开头锚定您的正则表达式模式 - ^subcategory/... 仅允许 subcategory/ 开头的路径。 subcategory/health 是这样,doctor/subcategory/health 不是。

标签: regex apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

我自己修好了,

解决方案如下: 我将 .htaccess 文件复制到子文件夹中,它运行良好,您可以为每个文件夹应用不同的重写规则。

【讨论】:

    猜你喜欢
    • 2012-11-22
    • 1970-01-01
    • 2012-08-20
    • 2012-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    相关资源
    最近更新 更多