-1

I've got a page, I'm currently trying to write a proper .htaccess file for.

At the moment I have this code:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

So that works all fine, but I want it to spit out the url with 'www' in front.

I've already tried that:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

But it obviously doesn't work like that.

I'd be very happy, if you could help me out, thanks a lot.

Noel
  • 1
  • Possible duplicate of [htaccess redirect to https://www](https://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www) – rob006 Apr 05 '18 at 23:15

1 Answers1

-1

You can try something like this.

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

or this

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
norcal johnny
  • 2,050
  • 2
  • 13
  • 17