views:

198

answers:

4

I want to do this: if they do https://example.com I want to redirect them to https://www.example.com (add the www.). I have tried oodles of things to no avail.

Redirect https://example.com/<anything> to https://www.example.com/<anything>
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

This code is in httpd.conf but has been tried in .htaccess and ssl.conf.

Can anyone help?

+1  A: 

Have you turned on Rewriting via RewriteEngine On or is mod_rewrite installed? Otherwise, your code should work.

Residuum
A: 
Gumbo
A: 

Use this:

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

Of course, don't forget to replace "www.example.com" with your own domain.

Adrián
A: 

We put the code in the virtual directive inside ssl.conf and it worked! Thanks for the help!