【问题标题】:LocationMatch negative expressionLocationMatch 否定表达式
【发布时间】:2023-03-22 18:01:01
【问题描述】:

我希望网站的密码保护只是 web 服务 URL 保持允许所有。

这个表达式在apache中完美运行,只需要反过来。

<LocationMatch "^(.*service).*$">
        AuthType Basic
        AuthName "Restricted Files"
        AuthUserFile /storage/www/xxxxx/.htpasswd
        Require valid-user
</LocationMatch>

我尝试了多种形式,但都不起作用。 我试过这个并且在调节器测试器中完美地工作,而不是在 apache (2.2) 中

<LocationMatch "^(?!.*service).*$">

如何否定那个表达式?

.htaccess 内容(如果有的话)。

RewriteEngine on
RewriteBase /


# ....
RewriteRule     txxxx/(.*)        index.php?config=main_lite&r=script/xxx/deliverData&url=$1

# rule 1 -- let these requests pass through (S=1 skips the next rule)
RewriteCond %{REQUEST_FILENAME} favicon.(gif|ico) [NC,OR]
RewriteCond %{REQUEST_FILENAME} .+\.(pdf|js|css|txt|jpg|jpeg|gif|png|bmp|ico|swf|html|log|svg|ttf|eot|woff|woff2)$ [OR]
RewriteCond %{REQUEST_URI} rsc/ [OR]
RewriteCond %{REQUEST_URI} index.php$
RewriteRule (.*) - [S=1]

# rule 2 - pass every request to index.php
RewriteRule .* index.php

【问题讨论】:

  • 我在您的 .htaccess 中没有看到任何密码保护。同时显示您的完整 &lt;LocationMatch... 标签。
  • 对不起,我添加了密码保护部分。

标签: regex apache apache-config locationmatch


【解决方案1】:

似乎 Apache 正则表达式支持太有限了..

但是,您可以轻松地“否定”您的表达式,方法是在封闭子句中定义您想要的所有内容(例如“Location”),然后在(非否定)LocationMatch 下恢复为“默认”设置。

类似这样的:https://serverfault.com/questions/591591/apache-locationmatch-regex-behaviour-does-not-seem-correct

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-20
    • 2014-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    • 2014-01-13
    • 1970-01-01
    相关资源
    最近更新 更多