Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm having trouble redirecting:

https://example.com to https://www.example.com.

I've currently got this and its not achieving the result I need and I'm not sure why:

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

I basically want to redirect everything to https://www.example.com

I appreciate any help.

share|improve this question
What result is it achieving? –  Ladadadada Mar 23 '12 at 15:24
@Ladadadada because there is no certificate for https://example.com you get an SSL warning, I was hoping the rewrite would overcome this? –  Abs Mar 23 '12 at 15:32

2 Answers 2

up vote 2 down vote accepted

Based on your comment you're trying to redirect in order to avoid a mis-matched URL SSL warning in the browser window. This cannot be done, as the redirect happens after the SSL handshake (because it uses a Location: response header to a request that won't be sent until the SSL handshake occurs and is accepted by the user).

Your best approach is:

  • Split example.com into a separate VirtualHost and use mod_alias as @HampusLi suggested
  • Purchase another certificate for example.com and apply it to this VirtualHost

Alternatively, you could get a SAN (Subject Alternate Name) certificate that works for both example.com and www.example.com.

share|improve this answer

You dont need mod_rewrite for this, you can use the much more lightweight built in module mod_alias with this simple syntax under the http vhost:

Redirect permanent / https://example.com/
share|improve this answer
Of course he means www.example.com –  gparent Mar 23 '12 at 15:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.