How to Redirect your site to https:// using .htaccess ?
Linux Dedicated Server allows you to host mulitple websites under your web hosting space. Linux Dedicated Server comes with full root access where you will be having control to make any changes at any time.
As a recent news, the new version of Chrome will mark all HTTP sites as ‘Not secure’ and prominently highlight this in the URL bar in an effort to create a more secure internet. Hence the necessity of SSL on domain names is vast increasing in the internet world.
Once you have purchased and installed an SSL certificate, you can configure your server to automatically redirect visitors to the secure version of your website.
In order to force your web traffic to use HTTPS, you need to edit the codes in the .htaccess file.
Kindly follow the below procedure to set redirection,
- Login to your cPanel account
- Go to “File Manager” under Files Section
- Go to document root [ public_html] of the domain where we want to set the https redirection
- In Right corner you can see “Settings” option
- Enable “Show Hidden Files (dotfiles)” and save it
- Open your .htaccess file if you already have one. If not, click on the button ‘File+’ on the upper left corner of the page and name the file .htaccess and click the button ‘Create New File’.
- Select the .htaccess file, and click ‘Edit’.
- You can give the following code to your .htaccess file.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
9. Finally, click Save Changes and Close.
That’s all. Visit your website now and you’ll automatically be re-directed to the HTTPS version.