Apache的HTTP重定向到https和WWW非WWW
基本上我想要的是重定向人要求使用HTTPS而不是HTTP
basically what i want is redirect al request to use HTTPS instead of http
我已经在我的htaccess的,到目前为止,它的工作很大: code:
I have this in my htaccess so far and it worked great: Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</ifModule>
高英时
今天有人注意到: http://www.mysite.com 重定向到并显示不安全的连接的thingie。
today someone noticed that when gowing to: http://www.mysite.com it redirects to and shows an unsecure connection thingie.
我的SSL的设置对非WWW域名:mydomain.com
My ssl is setup for non www domain: mydomain.com
所以,我需要确保所有站点的请求被发送到非WWW和https: 它工作正常,如果我把mysite.com重定向到 https://mysite.com
So i need to make sure all site requests are sent to non www and https: It works fine if i put mysite.com it redirects to https://mysite.com
但www.mysite.com它去HTTS://www.mysite.com并显示错误
but with www.mysite.com it goes to htts://www.mysite.com and shows the error
我需要什么添加到我的code重定向WWW非WWW,然后到SSL ?
what do i need to add to my code to redirect www to non www and then to ssl ?
您可以得到你从所需要的HTTP_HOST
You can get what you need from the HTTP_HOST
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
此方式,将获得的主机始终没有子域名。
This way it will get the host always without the subdomain.