【问题标题】:.htaccess, mod_rewrite and subdirectories.htaccess、mod_rewrite 和子目录
【发布时间】:2009-09-05 17:54:16
【问题描述】:

关于 .htaccess 文档,将 .htaccess 文件放在目录中应该会影响该目录和所有子目录。但我无法让它发挥作用:

我要文件,alice.html 和 bob.html(只打印“Alice”和“Bob”),和这个 .htaccess 在同一个目录(/tmp/rewrite):

RewriteEngine on
RewriteBase /tmp/rewrite
RewriteRule ^alice.html$ bob.html

当我尝试访问 /tmp/rewrite/alice.html 时,我得到“Bob” - 很好。

但是当我将同一个 html 文件放在子目录 /tmp/rewrite/sub 并尝试访问 /tmp/rewrite/sub/alice.html 时,我得到“Alice”。

我错过了什么?

【问题讨论】:

  • 如果 URL 路径与物理路径相同,则不需要 RewriteBase 指令。试试不带RewriteBase
  • @Gumbo:然后我得到 404 错误。

标签: apache .htaccess mod-rewrite


【解决方案1】:

这种行为是正常的。你告诉 apache 将 alice.html mod_rewrite 到 bob.html 中,以防它出现在为这些规则定义的“根”上。如果要将规则应用于其他文件夹,则必须应用更多规则,如下所示:

RewriteRule ^/sub/alice.html$ /sub/bob.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多