如何使用 htaccess 强制从 http 重定向到 https?

如何使用 htaccess 强制从 http 重定向到 https?

我需要使用 htaccess 强制从网站的 http 重定向到 https。

使用 Dreamhost 等共享主机时需要。

答案1

对于强制重定向我使用这个 htaccess

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

重定向域名.us ->https://domain.us

重定向domain.us/sub/ ->https://domain.us/sub/

相关内容