【问题标题】:Apache mod_rewrite: How to "whitelist" urls?Apache mod_rewrite:如何将网址“列入白名单”?
【发布时间】:2018-01-08 18:38:02
【问题描述】:

我正在使用 mod_rewrite 来获得更好的网址。所以目前访问页面有两种方式:

唯一可以访问该站点的方法应该是使用 mod_rewrite。换句话说,我想将某些 uri 列入“白名单”并阻止每个不同的 uri。

我想过有一个带有“END”标志的 RewriteRules 列表,所以如果上述规则都不匹配,最后一个将阻止请求。这行得通,但它也阻止了我的 index.php 站点。此外,这“感觉”不是最好的方法。

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting uri


    【解决方案1】:

    可以使用RewriteCond 来whilelist 某些页面,并使用RewriteRule 来捕获所有响应404 错误。

    # if the request uri is not /mypage.php and /otherpage.php
    RewriteCond %{REQUEST_URI} !^/(mypage|otherpage)\.php
    
    # if the request uri is not /startpage
    RewriteCond %{REQUEST_URI} !^/startpage
    
    # response 404 error
    RewriteRule ^ - [R=404,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-04
      • 2017-09-18
      • 1970-01-01
      • 2021-01-04
      • 1970-01-01
      • 1970-01-01
      • 2012-05-17
      • 1970-01-01
      相关资源
      最近更新 更多