Forcing HTTPS Redirects

Machine-translated (anthropic, claude-haiku-5-5) from the Chinese original. Read the original in 中文

Contents

Apache

Create a .htaccess file in the website root directory

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

Nginx

text
if ($server_port = 80) {
rewrite ^(.*)$ https://$host$1 permanent;
}

Comments