如何从http重定向到https

时间:2015-03-08 07:14:44

标签: php asp.net .htaccess http https

如何从http重定向到https:

1. redirect http://example.com to https://www.example.com
2. redirect http://www.example.com to https://www.example.com
3. redirect https://example.com to https://www.example.com

喜欢脸书,谷歌?

请帮助我使用.htaccess或其他代码。

3 个答案:

答案 0 :(得分:1)

要在单一规则中处理所有这3个重定向,您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码:

RewriteEngine On

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

RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]

答案 1 :(得分:0)

只需在下方添加.htaccess

即可
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

答案 2 :(得分:0)

guard le tvOSAppStoreUrl = URL(string: "com.apple.TVAppStore://itunes.apple.com/app/idXXXXXXX?mt=8") else {
  return
}

UIApplication.shared.open(url, options: [:], completionHandler: nil)