简体   繁体   English

将http重定向到https,将www重定向到非www?

[英]Redirect http to https and www to non-www?

I searched in Google for this and checked over 50 posts but none seems to work. 我在Google中搜索了此内容,并检查了50多个帖子,但似乎没有一个起作用。 Lets assume that I have a domain example.com. 假设我有一个example.com域。 What I want to do is redirect 我想做的就是重定向

http://www.example.com
https://www.example.com
http://example.com

to

https://example.com

Can anybody please help me?? 有人可以帮我吗? Any help would be appriciated. 任何帮助将被申请。

Note: I'm using cloudflare and I don't have access to conf file. 注意:我正在使用cloudflare,但无权访问conf文件。 I have access to .htaccess files. 我可以访问.htaccess文件。

EDIT1 :My htaccess looks like 编辑1 :我的htaccess看起来像

RewriteEngine On 
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]

You can try something like this: 您可以尝试如下操作:

RewriteEngine On

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

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

You can use this rule in Cloudfare: 您可以在Cloudfare中使用以下规则:

RewriteEngine On 

RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"' [OR]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM