【问题标题】:htaccess deny access specific url but with 1 exceptionhtaccess 拒绝访问特定的 url,但有 1 个例外
【发布时间】:2016-05-20 12:41:17
【问题描述】:

我想拒绝访问以 /mapname 开头的 url,从而阻止 /mapname/mapname2/mapname/file1 等 url。但是我想允许 1 个 url,例如 /mapname/mapname.php/something/something/something.php/something 。如何使用 htaccess 做到这一点?

为了拒绝访问,我使用了以下代码示例。这行得通,但我不知道如何允许特定的网址。

RewriteCond %{REQUEST_URI} /mapname
RewriteRule ^.*$ / [R=301,L]

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    在单个RewriteRule 中,可以使用负前瞻来做到这一点:

    RewriteRule ^mapname(?!/something\.php/allow/this/uri/?$) - [F,L,NC]
    

    【讨论】:

      【解决方案2】:

      你可以用这个:

      RewriteRule ^mapname/something\.php/allow/this/uri/?$ - [L]
      #Deny any other uri string starting with "/mapname
      RewriteCond %{REQUEST_URI} ^/mapname
      RewriteRule ^.*$ - [F,L]
      

      【讨论】:

      • 谢谢,这行得通!我选择另一个答案是正确的,因为它更紧凑:)
      猜你喜欢
      • 2011-01-12
      • 2013-10-07
      • 2021-01-30
      • 2016-03-23
      • 1970-01-01
      • 2017-08-14
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      相关资源
      最近更新 更多