【问题标题】:htaccess deny acces to all php files but redirect old non-existinghtaccess 拒绝访问所有 php 文件,但重定向旧的不存在
【发布时间】:2017-08-05 08:31:34
【问题描述】:

据我所知,L 标志只适用于mod_rewriteS 来重写规则。但是,我有一些旧的索引 php 页面,我想将它们重定向到新的 URL。我喜欢这样的无数行:

RewriteRule ^example.php(/?.*) /example/$1 [R=301,L]

这通常可以工作,但我的 .htaccess 中也有这段代码:

<Files *.php>
Order Deny,Allow
Deny from all
</Files>

我想知道,如果满足规则,是否可以跳过这个,只要上面提到的这两个标志不适用。

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite http-status-code-403


    【解决方案1】:

    您可以将所有特定的重定向规则保留在顶部,然后使用通用规则拒绝访问.php 文件,如下所示:

    RewriteEngine On
    
    # specific .php handlers
    RewriteRule ^example\.php(/.*)?$ /example/$1 [R=301,L,NC]
    
    # generic rule to deny .php files
    RewriteCond %{REQUEST_URI} !^/index\.php [NC]
    RewriteRule \.php$ - [F,NC]
    

    【讨论】:

      猜你喜欢
      • 2019-04-07
      • 2016-03-23
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      • 2015-07-30
      • 2017-08-14
      • 1970-01-01
      • 2014-03-25
      相关资源
      最近更新 更多