How to force use HTTPS and WWW in .htaccess file

If you have purchase SSL certificate for your website or want to use our SSL certificate for free.
You have to login into your website via ftp connection using software like filezilla, winscp.

Create a file name .htaccess (starting with dot and end on ss) and just paste the following code and change it to your domain name or tld in the file and click save.

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

  • How to force use HTTPS
  • 4 Users Found This Useful
Was this answer helpful?