首页 文章

htaccess - 如何将htaccess文件应用于子目录?

提问于
浏览
1

我有一个重写规则:

RewriteRule ^Catalog/Custom_Pages/([^\.]+)\.html$  http://www.domain.com/New/Catalog/Custom_Pages/Custom_Pages_Main.php?cp=$1 [R]

目录结构是domain.com/New/Catalog/

如果我省略RewriteRule前面的'Catalog',则不会重写URL . htaccess文件位于“新建”目录中 . 那么'New'的htaccess只适用于它的子目录,还是应用于所有子目录,以便'Catalog'可以省略?这可能是服务器设置吗?

2 回答

  • 3

    如果.htaccess文件位于 /New/ 文件夹中,则它将应用于此文件夹和所有子文件夹,但 RewriteRule 指令中的所有URL路径将为 relative/New/ 文件夹 .

    如果要从RewriteRule模式中省略 Catalog/ part,请尝试使用此规则:

    RewriteRule Custom_Pages/([^\.]+)\.html$  http://www.domain.com/New/Catalog/Custom_Pages/Custom_Pages_Main.php?cp=$1 [R]
    

    你当前的模式清楚地说"URL should start with Catalog"(检查正则表达式手册 ^ 的含义) .

    然后,上述规则可以应用于 Catalog/Custom_Pages/something.html 以及 Pink-Kitten/Custom_Pages/something.html .

  • 0

    该模式将从目录中匹配到页面的url,因此例如:

    http://www.domain.com/New/Catalog/Custom_Pages/test.html
    

    从目录/新建页面的路径是:

    Catalog/Custom_Pages/test.html
    

    然后,如果正则表达式模式匹配 Catalog/Custom_Pages/test.html ,则将应用规则,否则将不会应用该规则 .

    ps:如果 CatalogCustom_Pages 中有.htaccess,则会先测试他们的规则 .

相关问题