Apache mod_rewrite redirect for non secure requests to secure www. subdomain

If you're new here, you may want to subscribe to my RSS feed.
Thanks for reading my blog!

In many cases SSL certificates are issued for the "www." domain.
Then you'll want to have all links pointing to "www." domain otherwise you'll see Firefox's error message:

"Secure Connection Failed. The certificate is only valid for www.domain.com"

[code]
RewriteEngine on
#RewriteCond %{SERVER_PORT} ^80$

RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]

RewriteRule .* https://www.domain.com%{REQUEST_URI} [QSA,R=301,L]

[/code]

Tags: , , , , , ,

Leave a Reply