简体   繁体   中英

Redirect all requests with http to https

I need to redirect all requests with http to https. It is difficult to me to do with php headers. Is there any perfect way to do it?

You can use .htaccess to redirect users to a different URL. Include a .htaccess file with the following rules in www folder to direct incoming traffic from HTTP to HTTPS

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

A slightly different approach - again done in .htaccess

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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