用于 HTTPS 重定向的 Apache RewriteCond RewriteRule 组合帮助
需要一些帮助来将一些 RewriteRule 和 RewriteCond 组合在一起并防止重定向循环。
案例是强制所有传入请求都采用这些模式,以相同的模式重定向到 https://...
http://www.domain.com/admin --> https://www.domain.com/admin
http://www.domain.com/something/wp-login --> https://www.domain.com/something/wp-login
http://www.domain.com/something/wp-admin --> http://www.domain.com/something/wp-admin
http://www.domain.com/something/else/wp-login --> https://www.domain.com/something/else/wp-login
http://www.domain.com/something/else/wp-admin --> https://www.domain.com/something/else/wp-admin
但真正的技巧是我想用最少的语句来完成此任务。这是我到目前为止所拥有的,但它不太正确,并且在 /admin 情况下创建重定向循环,并在“wp-”情况下失败。
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^(/admin|wp-login|wp-admin) [NC]
RewriteRule ^(.*)$ https://www.domain.com$1 [R,L]
非常感谢这里的任何指示。
干杯。
Need some help for combining some RewriteRule's and RewriteCond's together and preventing redirect loops.
Case is to force all incoming requests to these patterns, to redirect to https:// with same pattern...
http://www.domain.com/admin --> https://www.domain.com/admin
http://www.domain.com/something/wp-login --> https://www.domain.com/something/wp-login
http://www.domain.com/something/wp-admin --> http://www.domain.com/something/wp-admin
http://www.domain.com/something/else/wp-login --> https://www.domain.com/something/else/wp-login
http://www.domain.com/something/else/wp-admin --> https://www.domain.com/something/else/wp-admin
But the real trick is that I'd like to accomplish this in the fewest statements. Here's what I have so far, but it's not quite right and creates redirect loops in the /admin cases and fails in the "wp-" cases.
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^(/admin|wp-login|wp-admin) [NC]
RewriteRule ^(.*)$ https://www.domain.com$1 [R,L]
Much obliged for any pointers here.
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上面的评论有助于摆脱重定向循环。我还尝试以多种方式简化前面的 RewriteCond,但除了上面的方法之外,什么都无法工作。
例如..为什么下面的 RewriteCond 不做同样的事情只是更简单..
在我看来这应该是以下所有内容的真实条件...
但由于某种原因 wp- url 与该不匹配条件/模式。
The comment above helped get rid of the redirect loops. I also tried to simplify the preceding RewriteCond in a number of ways but couldn't get anything but the above to work.
For example..why doesn't the below RewriteCond do the same thing only more simply..
Seems to me that should be a true condition for all of the following...
But for some reason the wp- urls don't match that condition/pattern.