htaccess在其他规则之前重定向301

时间:2017-09-22 07:27:43

标签: apache .htaccess redirect mod-rewrite

我的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>

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

1 个答案:

答案 0 :(得分:0)

工作解决方案:

(...)
# 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>
(...)