dots Created with Sketch.
Yogesh Chauhan's Blog

Forcing the domain to serve securely using HTTPS

in Miscellaneous on January 10, 2021

If you have added an SSL certificate to your domain, you can force all visits to your site to use HTTPS to ensure your traffic is secure.

You need to create/edit an .htaccess file on your server.

Where should the .htaccess file be created/located?

The .htaccess file should be located in your website’s primary directory.

If your site is ‘’, the .htaccess file would go in the /home/username/ directory. You can also confirm your site’s web directory in the panel.

The following forces any http request to be rewritten using https.

For example, the following code forces a request to to load

It also forces directly linked resources (images, css, etc.) to use https:

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

If this isn’t working for you, first check your line endings.

Copy/paste from your web browser into a text editor may not work right, so after pasting into your text editor you should delete each line break and add it back in (line break = return key).


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Jul 22 Is there a CSS parent selector? #Jul 22 Difference between :where and :is in CSS #Jul 22 Does :is() pseudo selector hint at CSS preprocessing in the future? #Jul 22 Control Scrolling with CSS Scroll Snap #Jul 21 Control rendering using CSS content-visibility property #Jul 21 How to use @supports rule in CSS?
You might also like these
Introduction to components and templates Part 2: Templates and viewsAngularHow to set the permissions on all files and folders in Mac?MiscellaneousWordPress get_posts ExamplesWordPressHow to create a Bootstrap style accordion using CSS and JavaScript?CSSA Quick Comparison of JOIN and Subquery in SQLSQL/MySQLHow to add CurrencyPipe in TypeScript file in Angular 9 Project?AngularHow to set opacity or transparency using CSS?CSSLearn how to use Self JOIN in SQL and MySQLSQL/MySQLHow to create a flip effect with CSS?CSS2 Ways We Can Write Multiple Line Commands in PHPPHPSQL GROUP BY StatementSQL/MySQLCheck if mixin is being called in a style rule or not in SCSSSCSS