YogeshChauhan.com
Forcing the domain to serve securely using HTTPS
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).

dreamhost

Leave a Reply

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to set opacity or transparency using CSS? #3 Pagination in CSS with multiple examples #4 How to make HTML form interactive and using CSS? #5 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #6 How to uninstall Cocoapods from the Mac OS?



Recently Posted

Feb 27 WordPress: How to display slider repeater fields in ACF? Feb 26 Simple Page Hit Counter in PHP Feb 26 Here’s what we can do with PHP date() function Feb 25 How to set default timezone using PHP? Feb 24 WordPress: How to loop through a repeater field in ACF? Feb 24 How to get ACF values from custom post type?



You might also like these

What Is a Graph Database?Misc3 Ways we can create URLSearchParams Objects in JavaScriptJavaScriptCanvas Drawing in HTML5HTMLadd_filter function in WordPressWordPressThe Drupal flowDrupalHow to detect if browser supports WebP format on server side PHP script?PHPHow to convert datetime to date format in JavaScript?JavaScriptHow to Pop an Alert Box in PHP?JavaScriptSolution to pod install fails with json error on Mac OS X 10.15 (or Mac OS Catalina)MiscHow to create two segues with two UIButtons on a single page (Swift 5.0)?SwiftSELF JOIN in PostgresPostgresSocial Media Colors: Sass VariablesMisc