开发者

Negate user space URL in Apache

开发者 https://www.devze.com 2023-01-28 17:29 出处:网络
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 re

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 Apach开发者_开发知识库e, 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!


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]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号