Apache version If you need to skip the whole site, type the following in the label of the configuration file of the website: RewriteEngine on RewriteCond %{SERVER_PORT} !^ 443$ RewriteRule ^(.*)?$ //%{SERVER_NAME}/$1 [L,R]
If a directory is forced to jump, the following code is used: RewriteEngine on RewriteBase /yourfolder RewriteCond %{SERVER_PORT} !^ 443$ #RewriteRule ^(.*)?$ //%{SERVER_NAME}/$1 [L,R] RewriteRule ^.*$ //%{SERVER_NAME}%{REQUEST_URI} [L,R]
Nginx version In the file for configuring port 80, write the following content. server { listen 80; server_name localhost; rewrite ^(.*)$ //$host$1 permanent; location / { root html; index index.html index.htm; }
PHP page jump: added in the website php page if ($_SERVER["HTTPS"] <> "on") { $xredir="//".$_ SERVER["SERVER_NAME"].$_ SERVER["REQUEST_URI"]; header("Location: ".$xredir); }
Common code snippet for separate page: It is more suitable to specify a separate https for a certain subpage. Add the following code to the page that needs to be forced to https to process http ->https <script language="JavaScript" type="text/JavaScript"> function redirect() { var loc = location.href.split(':'); if(loc[0]=='http') { location.href='https:'+loc[1]; } } onload=redirect </script> |