【问题标题】:.htaccess - Redirect with the following rules / conditions?.htaccess - 使用以下规则/条件重定向?
【发布时间】:2015-09-07 08:07:29
【问题描述】:

匹配以下规则的规则如下所示:

将所有非文件请求重定向到根目录(example.com/foo 或 example.com/foo/goo 到 example.com) 将所有不存在的文件请求重定向到根目录(example.com/not_exisiting_file.php 到 example.com) 将所有请求传递给现有文件。

htaccess 中的 mod-rewrite 会是什么样子?

谢谢

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    您可以在/.htaccess 文件中使用以下规则将所有不存在的文件请求重定向到根目录:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ http://example.com/ [R,NC,L] 
    

    【讨论】:

      【解决方案2】:

      对于 Apache 2.4,查看 FallbackResource 指令是否可以满足您的需求。

      它旨在用-d-f 取代以前使用RewriteCond

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-22
        相关资源
        最近更新 更多