Dark Cyber
Dark Cyber

Reputation: 2231

Redirect https non www to https www not working virtualhost

I have this configuration in virtualhost for redirect https non www to https www but this configuration is not working

So when I visit https://myweb.com/ it not redirect to https://www.myweb.com/

Listen 443
<VirtualHost *:443>
        RewriteEngine On
        RewriteCond %{HTTP_HOST} !^www\.
        RewriteRule (.*) https://www.myweb.com/$1 [R=301,L]

.... so on ....
</VirtualHost>

Is something wrong with my configuration?

Upvotes: 2

Views: 352

Answers (1)

Joe
Joe

Reputation: 4907

Try and use this rule instead:

RewriteEngine On

RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.myweb.com%{REQUEST_URI} [R=301,L,NE]

Make sure you clear your cache before testing this.

Upvotes: 2

Related Questions