Robbie
Robbie

Reputation: 9

How do I redirect all incoming requests to https?

Forgive me but I've been looking for answers all day. Trying and testing different things I can't seem to find the answer.

I have SSL for my domain and this is what my .htaccess looks like.

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

myexample.com and http://myexample.com redirects perfectly fine to https. Only problem is when I type www.myexample.com it doesn't redirect to https nor does typing http://www.myexample.com

Could any one help me or point me to the right direction?

Upvotes: 0

Views: 34

Answers (1)

René Pijl
René Pijl

Reputation: 4728

Your RewriteCond matches only hostnames starting with example.com. Try:

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

Also, www.example.com must be the ServerName or a ServerAlias of your name-based Virtual Host.

Upvotes: 1

Related Questions