How To Enable HTTPS  SSL Redirection From HTTP And Remove WWW?

 

 

How To Enable HTTPS  SSL Redirection From HTTP And Remove WWW? 1

If your website has SSL certificate, you can easily route visitors to the secured version (https) of your website to ensure the information is protected. To enable HTTPS and redirect all route requests from www to non-www version of your domain, follow the steps given below

 

Steps to force HTTPS for all sites in cPanel account

  1. Login to cPanel account
  2. Go to File manager and go to public_html folder
  3. Click to edit .htaccess file
  4. If you do not see .htaccess file, you have to change the settings of the File Manager to show hidden files. Follow these steps to make hidden files visible
  5. Click Settings located on the top right corner of File Manager
  6. Select both check boxes. One option is named as “Show hidden files”. Make sure you have checked the box.
  7. Click Go
  8. If you still cannot see .htaccess file, you need to create one and add code mentioned below
  9. In .htaccess file add the following code
  • RewriteEngine On
  • RewriteCond %{HTTPS} !=on
  • RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
  1. Click Save

Note: the above code verifies the initial request does not have HTTPS and rewrites the entire requested URL replacing HTTP:// with https://

For example

http://yoursite.com/subfolder/index.php will be replaced with

https://yoursite.com/subfolder/index.php).

 

If you are having multiple domains and want to force HTTPS for specific sites, follow the steps given below.

Steps to force HTTPS for a specific site

To enable HTTPS for a specific site, add the following code block in the .htaccess file.

  • RewriteEngine On
  • RewriteCond %{SERVER_PORT} 80
  • RewriteCond %{HTTP_HOST} ^hostingidol\.com$ [OR]
  • RewriteCond %{HTTP_HOST} ^www\.hostingidol\.com$
  • RewriteRule ^(.*)$ https://www.hostingidol.com/$1 [R,L]

 

If you want HTTPS to redirect for all sites in cPanel except a few or one, follow the steps given below

Steps to disable rewrite application rule for a specific site 

To disable HTTPS for a specific site, add the following code block in the .htaccess file.

  • RewriteEngine On
  • RewriteCond %{HTTP_HOST} ^(www\.)?hostingidol\.info
  • RewriteRule .* – [L]
  • RewriteCond %{HTTPS} !=on
  • RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

 

Some webmasters would want to force https for content in specific folders in the domain and not for the entire site. If that is the case, follow the steps given below

Steps to enable HTTPS for a specific subfolder

To enable HTTPS for a specific folder, add the following code block in .htaccess file

  • RewriteEngine On
  • RewriteCond %{HTTPS} !=on
  • RewriteRule ^/?subfolder/(.*) https://%www.hostingidol.com/subfolder/$1 [R,L]

Note- The HTTPS redirect is forced only for the folder specified in the code

 

Steps to enable HTTPS for a specific page

To enable HTTPS for a specific page, add the following code block in .htaccess file

  • RewriteEngine On
  • RewriteCond %{HTTPS} !=on
  • RewriteRule ^example\.html$ https://www.hostingidol.com/example.html [R,L]

 

Note– the HTTPS redirect will be forced only for the page mentioned in the code

If the page is located in a specific subfolder, only the RewriteRule syntax needs to be modified

  • RewriteRule ^test/example\.html$ https://www.hostingidol.com/test/example.html [R,L]

Note – In this test is the subfolder in which the page contents are located

 

You can also enable HTTPS for a specific page without pointing to a folder by following steps given below.

Steps to enable HTTPS for a specific file regardless of location 

Sometimes you will have pages with similar names in different folders. Instead of giving separate redirects, you can write one code that will force a redirect for specific pages with the same name.

  • RewriteEngine On
  • RewriteCond %{HTTPS} !=on
  • RewriteCond %{REQUEST_FILENAME} index.html
  • RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

Note– only file names that match with REQUEST_FILENAME parameter will be redirected to HTTPS.

Leave a Reply

Your email address will not be published. Required fields are marked *

Security code * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.