【问题标题】:How to tell apache to rewrite to another directory if file not found?如果找不到文件,如何告诉 apache 重写到另一个目录?
【发布时间】:2012-04-23 09:01:50
【问题描述】:

我需要知道如何修改我的 .htaccess 文件,以告诉 Apache 在未找到特定文件时查看另一个目录。在下面的示例中,目录 /dir 可能有数千个丢失的文件,其文件类型可能存在于 /dir2 中。

例如我有:

domain.com/dir/

如果找不到文件,请尝试

domain.com/dir2/

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    查看RewriteCond patterns 中的-f 以测试文件是否存在。因此,您将使用以下内容:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^dir/(.+)$ /dir2/$1 [L]
    

    如果文件不在 dir2 中,那么您会收到常规的 404 消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-18
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      相关资源
      最近更新 更多