Deprecated: Return type of Ai1wm_Recursive_Directory_Iterator::rewind() should either be compatible with FilesystemIterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/Rocket-migration-tool/lib/vendor/servmask/iterator/class-ai1wm-recursive-directory-iterator.php on line 37

Deprecated: Return type of Ai1wm_Recursive_Directory_Iterator::next() should either be compatible with DirectoryIterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/Rocket-migration-tool/lib/vendor/servmask/iterator/class-ai1wm-recursive-directory-iterator.php on line 44

Deprecated: Return type of Ai1wm_Extension_Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/Rocket-migration-tool/lib/vendor/servmask/filter/class-ai1wm-extension-filter.php on line 37

Deprecated: Return type of Ai1wm_Recursive_Exclude_Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/Rocket-migration-tool/lib/vendor/servmask/filter/class-ai1wm-recursive-exclude-filter.php on line 41

Deprecated: Return type of Ai1wm_Recursive_Exclude_Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/Rocket-migration-tool/lib/vendor/servmask/filter/class-ai1wm-recursive-exclude-filter.php on line 37

Deprecated: Creation of dynamic property ThirstyAffiliates::$failed_dependencies is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/thirstyaffiliates/thirstyaffiliates.php on line 160

Deprecated: Creation of dynamic property ThirstyAffiliates\Helpers\Plugin_Constants::$_MAIN_PLUGIN_FILE_PATH is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/thirstyaffiliates/Helpers/Plugin_Constants.php on line 72

Deprecated: Creation of dynamic property ThirstyAffiliates\Helpers\Plugin_Constants::$_PLUGIN_DIR_PATH is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/thirstyaffiliates/Helpers/Plugin_Constants.php on line 73

Deprecated: Creation of dynamic property ThirstyAffiliates\Helpers\Plugin_Constants::$_PLUGIN_DIR_URL is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/thirstyaffiliates/Helpers/Plugin_Constants.php on line 74

Deprecated: Creation of dynamic property ThirstyAffiliates\Helpers\Plugin_Constants::$_PLUGIN_DIRNAME is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/thirstyaffiliates/Helpers/Plugin_Constants.php on line 75

Deprecated: Creation of dynamic property ThirstyAffiliates\Helpers\Plugin_Constants::$_PLUGIN_BASENAME is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/thirstyaffiliates/Helpers/Plugin_Constants.php on line 76

Deprecated: Creation of dynamic property ThirstyAffiliates\Helpers\Plugin_Constants::$_CSS_ROOT_URL is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/thirstyaffiliates/Helpers/Plugin_Constants.php on line 78

Deprecated: Creation of dynamic property ThirstyAffiliates\Helpers\Plugin_Constants::$_IMAGES_ROOT_URL is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/thirstyaffiliates/Helpers/Plugin_Constants.php on line 79

Deprecated: Creation of dynamic property ThirstyAffiliates\Helpers\Plugin_Constants::$_JS_ROOT_URL is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/thirstyaffiliates/Helpers/Plugin_Constants.php on line 80

Deprecated: Creation of dynamic property ThirstyAffiliates\Helpers\Plugin_Constants::$_VIEWS_ROOT_PATH is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/thirstyaffiliates/Helpers/Plugin_Constants.php on line 82

Deprecated: Creation of dynamic property ThirstyAffiliates\Helpers\Plugin_Constants::$_TEMPLATES_ROOT_PATH is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/thirstyaffiliates/Helpers/Plugin_Constants.php on line 83

Deprecated: Creation of dynamic property ThirstyAffiliates\Helpers\Plugin_Constants::$_LOGS_ROOT_PATH is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/thirstyaffiliates/Helpers/Plugin_Constants.php on line 84

Deprecated: Creation of dynamic property ElementorPro\Plugin::$updater is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementor-pro/plugin.php on line 494

Deprecated: Creation of dynamic property RankMathPro\Analytics\Email_Reports::$views_path is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/seo-by-rank-math-pro/includes/modules/analytics/class-email-reports.php on line 49

Deprecated: Creation of dynamic property RankMathPro\Analytics\Email_Reports::$assets_url is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/seo-by-rank-math-pro/includes/modules/analytics/class-email-reports.php on line 50

Deprecated: version_compare(): Passing null to parameter #2 ($version2) of type string is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementor/core/experiments/manager.php on line 167

Deprecated: Return type of ElementskitVendor\Google\Model::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementskit/libs/composer/vendor/build/vendor/src/google/apiclient/src/Model.php on line 240

Deprecated: Return type of ElementskitVendor\Google\Model::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementskit/libs/composer/vendor/build/vendor/src/google/apiclient/src/Model.php on line 244

Deprecated: Return type of ElementskitVendor\Google\Model::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementskit/libs/composer/vendor/build/vendor/src/google/apiclient/src/Model.php on line 248

Deprecated: Return type of ElementskitVendor\Google\Model::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementskit/libs/composer/vendor/build/vendor/src/google/apiclient/src/Model.php on line 257

Deprecated: Return type of ElementskitVendor\Google\Collection::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementskit/libs/composer/vendor/build/vendor/src/google/apiclient/src/Collection.php on line 19

Deprecated: Return type of ElementskitVendor\Google\Collection::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementskit/libs/composer/vendor/build/vendor/src/google/apiclient/src/Collection.php on line 32

Deprecated: Return type of ElementskitVendor\Google\Collection::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementskit/libs/composer/vendor/build/vendor/src/google/apiclient/src/Collection.php on line 26

Deprecated: Return type of ElementskitVendor\Google\Collection::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementskit/libs/composer/vendor/build/vendor/src/google/apiclient/src/Collection.php on line 36

Deprecated: Return type of ElementskitVendor\Google\Collection::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementskit/libs/composer/vendor/build/vendor/src/google/apiclient/src/Collection.php on line 13

Deprecated: Return type of ElementskitVendor\Google\Collection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementskit/libs/composer/vendor/build/vendor/src/google/apiclient/src/Collection.php on line 41

Deprecated: Creation of dynamic property ElementsKit\Libs\Updater\Edd_Warper::$beta is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementskit/libs/updater/edd-warper.php on line 45

Deprecated: Creation of dynamic property Elementor\ElementsKit_Extend_Advanced_Tooltip::$url is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/elementskit/modules/advanced-tooltip/extend-controls.php on line 6

Deprecated: Creation of dynamic property SyntaxHighlighter::$brush_names is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter.php on line 248

Deprecated: Creation of dynamic property SyntaxHighlighter::$specialchars is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter.php on line 326
[2 Best Ways] How to Force HTTPS using .htaccess | Force SSL
wprecommend logo

Force HTTPS using .htaccess File

how-to-force-https-using-htaccess

How to Force HTTPS using .htaccess?

HTTPS stands for HyperText Transfer Protocol Secure, a protocol for secure communication between your website server and computer network.

Installed an SSL certificate for your website and your website still redirecting over HTTP? Don’t worry we are here to solve your issue on how to force HTTPS using .htaccess file.

After installing SSL your website is available in both HTTP and HTTPS versions. But we strongly recommend you to use only HTTPS version to encrypt and secure your server. Hosting providers allow you to force https over HTTP.

Why Use HTTPS over HTTP?

You may wonder why we should use HTTPS over HTTP. Nowadays website owners are preferring to use https and they are migrating from HTTP to HTTPS for the following reasons:

  • HTTPS is more secure than HTTP and builds a secure connection between the website server and the web browser.
  • Enabling HTTPS gives you a secure padlock, which builds trust on your site.
  • Google gives HTTPS sites an additional ranking boost on Google search.
  • HTTP/2 protocol gives you faster speed loading in browser end.
  • Enabling SSL is additional security for your website.

How to Redirect HTTP to HTTPS in WordPress Using .htaccess File

There are lots of options available for you to force HTTPS in WordPress. In this particular post, we will talk about how to redirect HTTP to HTTPS in WordPress using the .htaccess file.

force-HTTPS-using-htaccess

You can redirect all your traffic via .htaccess file using 301 permanent redirects. Your all old URLs will be replaced with the new one automatically after applying the below steps:

  • Go to your hosting Cpanel → File Manager, select the public_html folder and find .htacess file.
  • If you don’t have already create a file named .htaccess and open it in edit mode.
  • Scroll down and insert the following lines of code below it:
RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  • Save the changes.
If you don’t able to see (.) files on your file manager. Click on the settings icon and enable ‘show hidden files’ option shown in screenshot.
file-manager-show-hidden-files

Adding the above code in your website root folder, .htaccess file force HTTPS for your entire site. Let’s see how you can force SSL on a specific domain or subdirectory.

1. Force HTTPS for a Specific Folder or Subdirectory

You can force HTTPS on a specific folder or subdirectories using .htaccess file. Make sure to create a new .htaccess file for that specific directory or folder which you want to make HTTPS enabled.

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^(folder1|folder2|folder3) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Let’s say you want to secure “yourdomain.com/folder1” using .htaccess. All you have to do is create a new .htaccess file inside the “folder1” folder and put the code on it.

Don’t forget to change “folder1, folder2, folder3” with your original folder name.

2. Force HTTPS on a Specific Domain

Let’s assume you have two different websites http://website1.com and http://website2.com, but both websites access the same website. Now you want to redirect HTTP to HTTPS on “website1.com” only. So what you have to do is, put the code on your .htaccess file for the specific domain.

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^website1.com [NC] 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Make sure to replace ‘website1.com’ to your actual domain name.

After applying all the changes clear your website cache and reload your website over HTTP. Magic right? It automatically redirects to HTTPS over HTTP.

Conclusion

Awesome, now you have redirected all your visitors to HTTPS from HTTP automatically. Visitors will see a secure icon before your domain name.

Depending on your website CMS (Content Management System), there will be some ways to enable SSL on your website. So your website can securely show you encrypted content over HTTPS.

Like, WordPress and Prestashop CMS use some plugin to enable that feature automatically and modify the .htaccess file to force HTTPS over HTTP.

Do you know any additional steps to force HTTPS using .htaccess file in WordPress? Share your thoughts on the comment section. Looking forward to your ideas, questions or suggestions.

Don’t forget to check How to Debug and Fix 503 Service Unavailable Error in WordPress.

Like it? Share with your friends!

Sanjay Samanta

Sanjay Samanta

I’m Sanjay Samanta the founder & CEO of Billions Ideas. I am a professional digital marketer who believes in done over perfect. I help people to make their brand and grow their business online by leveraging the power of strategic content marketing.

Leave a Comment

Sanjay Samanta
I’m Sanjay Samanta the founder & CEO of Billions Ideas. I am a professional digital marketer who believes in done over perfect. I help people to make their brand and grow their business online by leveraging the power of strategic content marketing.

Deprecated: Use of "parent" in callables is deprecated in /home2/sanjayhg/public_html/wprecommend.com/wp-content/plugins/wp-rocket/inc/Dependencies/Minify/JS.php on line 127