【问题标题】:How do I make a url forbidden in apache mod_rewrite, based on the query string?如何根据查询字符串在 apache mod_rewrite 中禁止 url?
【发布时间】:2023-03-25 07:38:02
【问题描述】:

如何在 apache 中禁止以下网址;

main/index.php?site=ing

我尝试了以下方法;

RewriteRule ^main/index.php?site=ing - [F]

但没有运气......

【问题讨论】:

  • 我在标题和标签中都添加了“查询字符串”,因此搜索查询字符串和 mod_rewrite 问题的人会找到这个。

标签: apache mod-rewrite query-string


【解决方案1】:

cannot match a query string in the RewriteRule,你该做的

RewriteCond %{QUERY_STRING} site=ing     #Adjust the regexps with anchors
RewriteRule ^main/index.php - [F]

【讨论】:

    【解决方案2】:

    应该这样做:

    RewriteCond %{QUERY_STRING} (^|&)site=ing(&|$)
    RewriteRule ^main/index\.php$ - [F]
    

    【讨论】:

      【解决方案3】:

      另一个非 apache 解决方案是在 index.php 文件中执行此操作。

      在页面顶部添加类似的内容。

      if(isset($_GET['site']) && $_GET['site'] == 'ing'){
          header('HTTP/1.1 403 Forbidden');
          exit();
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-07-27
        • 1970-01-01
        • 2011-03-28
        • 1970-01-01
        • 1970-01-01
        • 2012-10-15
        • 1970-01-01
        • 2012-08-30
        相关资源
        最近更新 更多