3

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?

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

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

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 https://stackoverflow.com/questions/5256718/how-to-redirect-http-example-com-to-http-www-example-com/5256747#5256747 . 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]
  • 3
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy