AriehGlazer
AriehGlazer

Reputation: 2320

problem with RewriteRule and apache

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

Upvotes: 0

Views: 153

Answers (3)

pixeline
pixeline

Reputation: 17984

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.

Upvotes: 0

Gumbo
Gumbo

Reputation: 655755

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).

Upvotes: 1

pixeline
pixeline

Reputation: 17984

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]

Upvotes: 1

Related Questions