【问题标题】:.htaccess - whitelist allowed URLs.htaccess - 白名单允许的 URL
【发布时间】:2015-08-15 08:23:41
【问题描述】:

我有一个简单的 PHP webapp,并且想限制用户可以访问几个 PHP 文件和一个或两个目录的 URL。任何未在 .htaccess 中列入白名单的 URL 都应被拒绝。

示例白名单:

/
/assets/*
index.php
profile.php
favicon.ico

这怎么可能最容易?

谢谢。

【问题讨论】:

    标签: php .htaccess url-rewriting


    【解决方案1】:

    一个简单的RewriteRule 在你的根 .htaccess 中可以工作:

    RewriteEngine On
    
    RewriteRule !^(index\.php|profile\.php|favicon\.ico|assets/.*)?$ - [F,NC]
    

    【讨论】:

      【解决方案2】:

      这就是我做类似事情的方式。特定文件,然后是文件夹。

      RewriteCond $1 !^(index\.php|robots\.txt|style\.css|sitemap\.xml)
      RewriteCond %{REQUEST_URI}  !/img/ [NC]
      RewriteRule ^(.*)$ - [F]
      

      【讨论】:

        猜你喜欢
        • 2016-06-05
        • 2013-06-11
        • 1970-01-01
        • 2013-08-10
        • 1970-01-01
        • 1970-01-01
        • 2014-02-20
        • 1970-01-01
        • 2012-07-15
        相关资源
        最近更新 更多