Apache 中的否定用户空间 URL

发布于 2024-10-05 05:08:56 字数 972 浏览 0 评论 0原文

我遇到过一种情况,我尝试使用 Apache 的 RedirectMatch 指令将所有用户重定向到 HTTPS URL 除了单个(Linux)用户访问自己的网络空间。我找到了一段否定 username: 的正则表达式代码,

 ^((?!andy).)*$

但是当我尝试在指令中使用它时:

RedirectMatch ^((?!andy).)*$ https://www.example.com/

URL:

http://www.example.com/~andy/

仍然被重定向到 HTTPS URL:

https://www.example.com/

当我希望它忽略重定向时。 我不是正则表达式(或 Apache)方面的专家,因此任何帮助完成这项工作的帮助将不胜感激。

谢谢, 斯蒂芬

编辑: 好吧,情节变得更复杂了...如果我注释掉这一行:

# RedirectMatch ^((?!andy).)*$ https://www.example.com/

并重新启动 Apache,然后尝试 URL:

http://www.example.com/andy

我会得到 404 响应,这是预期的。但是,如果我尝试 URL:

http://www.example.com/~andy

重定向被触发,我被重定向到:

https://www.example.com/

正如我所说,重定向被注释掉,我已经重新启动了服务器。怎么会发生这种事呢?所以这不仅仅是一个正则表达式的问题,Apache 似乎在没有指令的情况下进行重定向!

I have a situation where I am trying to use Apache's RedirectMatch directive to redirect all users to a HTTPS URL except a single (Linux) user accessing there own webspace. I have found a piece of regular expression code that negates the username:

 ^((?!andy).)*$

but when I try using it in the directive:

RedirectMatch ^((?!andy).)*$ https://www.example.com/

the URL:

http://www.example.com/~andy/

still gets redirected to the HTTPS URL:

https://www.example.com/

When I want it to ignore the redirection.
I am not an expert in regular expressions (or Apache), so any help in getting this working would be greatly appreciated.

Thanks,
Stephen

Edit:
OK, the plot thickens... if I comment out the line:

# RedirectMatch ^((?!andy).)*$ https://www.example.com/

and restart Apache, and then try the URL:

http://www.example.com/andy

I get a 404 response, which is expected. But, if I try the URL:

http://www.example.com/~andy

The redirect is triggered and I am redirected to:

https://www.example.com/

and as I said, the redirect is commented out and I have restarted the server. How can this happen? So this is not just a regex thing, it seems Apache is redirecting without instruction!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彼岸花似海 2024-10-12 05:08:56

也许有类似的事情? (使用 mod_rewrite 而不是 mod_alias)

RewriteCond %{REQUEST_URI} !^/~andy(/|$) ...
RewriteCond %{SCRIPT_URI} ^http:
RewriteRule ^/(.*) https://mysite.com/$1 [R=307]

Something along the lines of this maybe? (Uses mod_rewrite instead of mod_alias)

RewriteCond %{REQUEST_URI} !^/~andy(/|$) ...
RewriteCond %{SCRIPT_URI} ^http:
RewriteRule ^/(.*) https://mysite.com/$1 [R=307]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文