使用htaccess将http://www,http://和https://www重定向到https: [英] Using htaccess to redirect http://www, http:// and https://www to https:

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

问题描述

在我的网站上,我已经在域的非www版本上安装了SSL证书.我想使用htaccess将http www,http非www和https www重定向到https://

On my site I have installed an SSL certificate on the non www version of the domain. I would like to use htaccess to redirect http www, http non www and https www to https://

我可以将www改为非www,但是https www不会重定向到https non www.这是我的htaccess文件中的内容:

I have the www to non www working but the https www does not redirect to https non www. Here is what I have in my htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ link [R=301,L]

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https link [R,L]

有人可以帮我弄清楚我所缺少的吗?

Can anyone help me figure out what I am missing?

Sharon

推荐答案

您可以使用:用于http或https,带或不带www-> https不带www

You can use: for http or https, with or without www -> https without www

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

反之:对于http或https,带或不带www-> 带有www的https

And for the opposite: for http or https, with or without www -> https with www

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

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

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