Rajeesh
Rajeesh

Reputation: 43

Add www to urls having HTTPS

I need to add www to all the url which doesn't have the www at the starting(site is build in drupal). I have done the same for http request using the following code in htaccess file.

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Now I want to add the same for urls having https, like I need to redirect https://example.com to https://www.example.com.

I have tried several methods without any success. Please help me at the earliest as possible. Any help will be much appreciated.

Upvotes: 0

Views: 65

Answers (2)

Jon Lin
Jon Lin

Reputation: 143886

Change your rule to:

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}:s (on:(s)|off:s)
RewriteRule ^ http%2://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Upvotes: 0

anubhava
anubhava

Reputation: 785156

You can replace your rule with this:

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Upvotes: 1

Related Questions