<VirtualHost *:80>
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
server {
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://$host$request_uri;
}
<Connector
port="80"
redirectPort="443" />
$SERVER["socket"] == ":80" {
url.redirect = ("" => "https://${url.authority}${url.path}${qsa}")
}
go func() {
redirectToHTTPS := func(w http.ResponseWriter, req *http.Request) {
http.Redirect(w, req, "https://"+req.Host+req.RequestURI, http.StatusMovedPermanently)
}
srv := {{'&'}}http.Server{
Handler: http.HandlerFunc(redirectToHTTPS),
ReadTimeout: 60 * time.Second, WriteTimeout: 60 * time.Second,
}
log.Fatal(srv.ListenAndServe())
}()
[http.middlewares]
[http.middlewares.redirect-to-https.redirectScheme]
scheme = "https"
[http.middlewares.hsts-header.headers]
[http.middlewares.hsts-header.headers.customResponseHeaders]
Strict-Transport-Security = "max-age=63072000"
redirect scheme https code 301 if !{ ssl_fc }
<VirtualHost *:80>
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
安装rewrite模块,下载模块:
https://www.iis.net/downloads/microsoft/url-rewrite