Force non-www and https via htaccess

前端 未结 3 1121
醉话见心
醉话见心 2020-12-14 08:53

I\'m trying to force a user to be redirected to the non-www website, and, force https.

I\'ve got this which sort of work, but doesn\'t force https, when http is ente

3条回答
  •  醉话见心
    2020-12-14 09:16

    Based on Gumbo's comment : "the TLS/SSL connection is established and certificate is validated before it is handed down to HTTP and the HTTP redirection takes place" I gave this a try (which seems to work):

    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$ https://www.blahblah.com/$1 [R,L]
    
    RewriteCond %{HTTP_HOST} ^www\.blahblah\.com [NC]
    RewriteRule ^(.*)$ https://blahblah.com/$1 [L,R=301]
    

    please tell me if there is something wrong with this approach.

提交回复
热议问题