0

I'm looking for a way to redirect users to https://domain.com whether they type the www or not

I'm using a shared host for a drupal website so i don't have access to virtual host config files. A let's encrypt certificate if included with the hosting package
Right now the website can be accessed both with http and https depending on what you type in the browser.
In looking for a solution to force redirection to https i found this section in the in the .htaccess file that redirects users who type the www. to https://domain.com

# To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  # uncomment the following:
   RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
   RewriteRule ^ https%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

Now i'm looking for a way to redirect when typing http://domain.com without the www.

Do i need to put another rule somewhere in addition to the line i uncommented or is there some other way to do this ?

1

You could use something like this:

 RewriteCond %{HTTPS} !=on
 RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L,NE]
|improve this answer|||||
0

I'm using this piece of code for both situations (with and without www.):

RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www.DOMAINNAME.com* RewriteRule ^(.*)$ https://DOMAINNAME.com/$1 [L,R=301]

And it works fine

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.