views:

53

answers:

3

I have a SSL certificate that is registered to my www domain, but all my urls point to my domain without www. i tried this sentence:

RewriteRule ^[https://mydomain.org](.*)$ https://www.mydomain.org$1 [R=301,nc]

but for some unknown reason, it also redirects all the calls made to http://mydomain.org as well. i realy cant think of a reason for this

+1  A: 

Someone should correct me if i'm wrong but i don't think the RewriteRule directive has access to the protocol part of the requested uri. Try this instead:

RewriteCond %{HTTP_HOST} ^https://domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
pixeline
now it doesn't do any redirects what so ever (although i understand what you did and it seems it should work)
XiroX
A: 

Try this rule:

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]

But the invalid certificate message won’t go away since the SSL connection is accomplished before HTTP is taking part (since HTTPS is HTTP over SSL/TSL).

Gumbo
A: 

How about detecting the server port?

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

so litterally, if you are connecting to https (since you are using port 443) the url will have WWW.

pixeline