【问题标题】:htaccess redirect 301 before other ruleshtaccess 在其他规则之前重定向 301
【发布时间】:2017-09-22 07:27:43
【问题描述】:

我的 htaccess 是这样的:

# Prevent directory listings
Options -Indexes

redirect 301 /old.html http://blablabla.pl/new
redirect 301 /other-page.html http://blablabla.pl/new-page
redirect 301 /xxx.html http://blablabla.pl/zzz

# Prevent visitors from viewing files directly
<FilesMatch "\.(sdb|md|html|txt)$">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
    </IfModule>
</FilesMatch>

# URL rewrites
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(inc/|themes/|tmp/).*\.(php|html)$ - [F,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
</IfModule>

我正在使用 CMS,它使用 html 文件作为模板(有变量、php 代码等)。在这个 CMS 的 htaccess 中,有一些规则可以防止访问者直接查看 html 文件。我将一页移至此 CMS,并希望从旧页面进行 301 重定向,但它不起作用 - 我收到 403 禁止错误。有没有办法在其他规则之前执行 301 重定向?

【问题讨论】:

  • 评论 Options 行和所有 FilesMatch 并重新测试您的 301 规则。
  • 这可行,但不是解决方案。
  • 第一次测试,看看它是否有效。这仅用于测试目的。
  • 是的 - 它可以工作(即使没有评论选项行)。
  • 好的,你能澄清一下FilesMatch 应该做什么吗?

标签: apache .htaccess redirect mod-rewrite


【解决方案1】:

工作解决方案:

(...)
# Prevent visitors from viewing files directly
<FilesMatch "\.(sdb|md|html|txt)$">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
    </IfModule>
</FilesMatch>

<FilesMatch "(old\.html)|(other-page\.html)|(xxx\.html)">
    Allow from all
    Satisfy any
</FilesMatch>
(...)

【讨论】:

    猜你喜欢
    • 2010-12-22
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 2012-12-24
    • 1970-01-01
    相关资源
    最近更新 更多