YogeshChauhan . com

Forcing the domain to serve securely using HTTPS

in Misc 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 ‘example.com’, the .htaccess file would go in the /home/username/example.com 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 http://example.com to load https://example.com.

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 uninstall Cocoapods from the Mac OS? #4 How to add Read More Read Less Button using JavaScript? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

May 5 Use inline if to make a shorter conditional syntax in React May 4 What is Conditional Rendering in React? May 3 How does @extend rule work in SCSS (Sass)? May 2 How different is Handling Events in React vs HTML DOM? May 2 How to create bouncing balls using HTML canvas and JavaScript? Apr 30 HTML canvas methods

You might also like these

File System Integrity: How to Keep an Eye on Your Files and Folder Change?MiscThe 7 Security Objectives of Any Organization for IT and Network SecurityMiscHow to draw an SVG path on scroll using JavaScript?JavaScriptHow to enable and disable button using JavaScript?JavaScriptThe Complete Basic Explanation of PHP SessionsPHPHow to avoid element shift on border change while hovering in CSS?CSSHow to create a Star Ratings using CSS?CSSHow to uninstall Cocoapods from the Mac OS?MiscSome EASY-to-Understand CSS media query examplesCSSIf statement shorthand examples in JavaScriptJavaScriptDebugging in WordPress Part 2: WP_DEBUG_LOG and WP_DEBUG_DISPLAYWordPressThe fundamental difference between HAVING and WHERE clauses in PostgresPostgres