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 server SSL pages from https://example.com. If a user types in https://www.example.com, I want to redirect. I've the got rewrite rule working, but chrome displays an error message because the server identifies itself as example.com instead of www.example.com, so the rewrite rules don't execute.

Is there any way around this using apache virtual hosts, or do I need multiple certificates/a wildcard certificate?

share|improve this question

migrated from stackoverflow.com Jul 9 '11 at 10:50

This question came from our site for professional and enthusiast programmers.

This is not a programming question. Please ask this sort of thing on serverfault or webmasters. –  Flimzy Jul 9 '11 at 10:38
You'll need multiple certificates or a certificate with multiple CommonName or SubjAltname attributes. Also see wiki.apache.org/httpd/NameBasedSSLVHostsWithSNI and httpd.apache.org/docs/current/ssl/ssl_intro.html#ssl –  joschi Jul 9 '11 at 10:40

1 Answer 1

Like given in other answers here, you have an issues with your certificate.

For the time being you might want to consider using Mod_Rewrite also in this case.

Have look at my answer at How to Redirect http://example.com to http://www.example.com . Be aware of that in that case it was related to HTTP, not HTTPS. Simply make sure you put https:// instead of http:// in the RewriteRule.

RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*) https://example.com/$1 [R=301,L]
share|improve this answer
Unless he has a wildcard certificate this will lead into a certificate error, or not? "Invalid certificate" because the host does not fit with the host in the certificate (with and without www) –  strauberry Jul 9 '11 at 11:12

Your Answer


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