Apache 中的否定用户空间 URL
我遇到过一种情况,我尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许有类似的事情? (使用 mod_rewrite 而不是 mod_alias)
Something along the lines of this maybe? (Uses mod_rewrite instead of mod_alias)