简体   繁体   English

将所有带有http的请求重定向到https

[英]Redirect all requests with http to https

I need to redirect all requests with http to https. 我需要将所有带有http的请求重定向到https。 It is difficult to me to do with php headers. 我很难用php标头来做。 Is there any perfect way to do it? 有什么完美的方法吗?

You can use .htaccess to redirect users to a different URL. 您可以使用.htaccess将用户重定向到其他URL。 Include a .htaccess file with the following rules in www folder to direct incoming traffic from HTTP to HTTPS 在www文件夹中包含具有以下规则的.htaccess文件,以将传入流量从HTTP定向到HTTPS

RewriteEngine On
RewriteCond %{HTTPS} !on$
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

A slightly different approach - again done in .htaccess 稍微不同的方法-再次在.htaccess完成

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

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

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