HTTPS Redirection in HTML or PHP or Coding websites

HTTPS Redirection in HTML or PHP or Coding websites

HTTPS Redirection in HTML or PHP or Coding websites

Please: Note That SSL will take 48 to 72 hours to install on our server after changing the name server.

  • After 72 Hours, Now you are having a Cpanel with an installed SSL Certificate by a server, the next step is to redirect HTTP to HTTPS for safety. Before we move into the redirecting process, you need to edit the .htaccess file. If you have already done or know how to edit the .htaccess file, then you can directly skip to Htaccess redirect to HTTPS steps.
  • Login to cPanel.
  • Files > File Manager > Public_html
  • Now select the domain name you want to access (this step is for addon domain or having more than one domain in Cpanel or account if you have had one website/domain just skip this step).
  • Find .htaccess file if .htaccess not available Check “Show Hidden Files (dotfiles)”.

  • Click save & now look for the .htaccess file.
  • Right-click on the .htaccess file and click on “Edit” on the menu.
  • A dialogue box may pop up asking about encoding. Click the “Edit” button to continue & Edit the file.
  • Right-click on the .htaccess file and click on “Edit” on the menu.

1. Redirect All Web Traffic
If you have existing code in your .htaccess, add the following:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

2. Redirect Only a Specific Domain
For redirecting a specific domain to use HTTPS, add the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
3. Redirect Only a Specific Folder

Redirecting to HTTPS in a particular folder, add the following:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.yourdomain.com/folder/$1 [R,L]

Note: Replace “yourdomain” with your actual domain name wherever required. Also, in the case of the folder, replace /folder with the real folder name.

Final Step

“Save Changes” when done. Test your website to make sure it is done correctly. In case, there is an error, restore to the previous version and try again. Once you are done, click “Close” to close the window.