通过 htaccess 将所有 http 和 https 非 www URL 重定向到 https://www.xyz.com [英] Redirect all http AND https non-www URLS to https://www.xyz.com via htaccess

查看:28
本文介绍了通过 htaccess 将所有 http 和 https 非 www URL 重定向到 https://www.xyz.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于太长和太复杂的原因(它涉及几层公司繁文缛节,导致其他人没有购买我请求的通配符 SSL 证书),我必须设置一个域来将所有请求重定向到 https://www.xyz.com – 使用 www 子域的安全协议.

For reasons much too long and complex to get into (it involves several layers of corporate red tape resulting in someone else not purchasing a wildcard SSL certificate I requested), I have to set up a domain to redirect all requests to https://www.xyz.com – secure protocol with the www subdomain.

所以:http://xyz.comhttp:///www.xyz.comhttps://xyz.com 都应该重定向到 https://www.xyz.com.

So: http://xyz.com, http://www.xyz.com, and https://xyz.com should ALL redirect to https://www.xyz.com.

我的 .htaccess-fu 充其量很弱,我似乎无法让它发挥作用.注意:如果这有所作为,则托管在 Media Temple 上.

My .htaccess-fu is weak at best and I can't seem to get this to work. Note: hosting is on Media Temple if that makes a difference.

到目前为止,我的 .htaccess 文件看起来像这样:

So far, my .htaccess file looks like so:

RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://www.xyz.com/$1 [R,L]

RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

http://xyz.comhttp://www.xyz.com 正在重定向到 https://www.xyz.com,所以耶.但是,https://xyz.com不会重定向到 https://www.xyz.com 并因此抛出安全警告页面:

Both http://xyz.com and http://www.xyz.com are redirecting to https://www.xyz.com, so yay. However, https://xyz.com is not redirecting to https://www.xyz.com and is thus throwing a security warning page:

这可能不是您要找的网站!
您试图访问 xyz.com,但实际上您访问了一个自称为 www.xyz.com 的服务器.这可能是由服务器上的错误配置或更严重的事情引起的.您网络上的攻击者可能会试图让您访问 xyz.com 的虚假(并且可能有害)版本.
您不应继续,尤其是如果您之前从未见过此站点的此警告.

This is probably not the site you are looking for!
You attempted to reach xyz.com, but instead you actually reached a server identifying itself as www.xyz.com. This may be caused by a misconfiguration on the server or by something more serious. An attacker on your network could be trying to get you to visit a fake (and potentially harmful) version of xyz.com.
You should not proceed, especially if you have never seen this warning before for this site.

如果能帮助我度过最后的难关,我们将不胜感激!

Any help in getting me past this one final hump would be muchly appreciated!

推荐答案

如果未来有人(HELLO PEOPLE OF THE FUTURE)偶然发现这个问题,我问了同样的问题,并在 Server Fault 上得到了回答.

In case anyone from the future (HELLO PEOPLE OF THE FUTURE) stumble across this, I asked the same question and had it answered over at Server Fault.

>

简短版本:不可能.

Short version: impossible.

长版:https://serverfault.com/questions/523199/redirect-all-http-and-https-non-www-urls-to-https-www-example-com-via-htaccess

这篇关于通过 htaccess 将所有 http 和 https 非 www URL 重定向到 https://www.xyz.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆