windows下apache服务器网站http链接如何全部跳转https链接

2025-04-07 17:19:31
推荐回答(1个)
回答1:

网站根目录新建 .htaccess

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]

301跳转

RewriteEngine on

RewriteBase /

RewriteCond %{SERVER_PORT} !^443$

RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L]

站点绑定多个域名,只允许域名跳转

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

RewriteCond %{HTTP_HOST} ^example.com [NC,OR]

RewriteCond %{HTTP_HOST} ^www.example.com [NC]

RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]