Skip to main content

force https for a given website and not all hosted accounts

Comments

5 comments

  • Eminds
    To force all web traffic to use HTTPS insert the following lines of code in the .htaccess file in your website"s root folder. Important:If you have existing code in your .htacess, add this above where there are already rules with a similar starting prefix.
    RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    Be sure to replace www.example.com with your actual domain name. To force a specific domain to use HTTPS, use the following lines of code in the .htaccess file in your website's root folder:
    RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    Make sure to replace example\.com with the domain name you're trying force to https. Additionally, you need to replace example.com with your actual domain name.
    0
  • trucmuche
    Thanks ! So, to ensure that I understand correctly your answer (because I'm not sure to understand perfectly the difference between the two alternatives you're talking about - what's the difference ?)... I would like to redirect the HTTP visitors of my subdomain to HTTPS address (when they try to access my website using HTTP, switch them to HTTPS). So I have to put a .htaccess file in the /home/mydomain/subdomain.example.com/ folder and write inside :
    RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://subdomain.example.com/$1 [R,L]
    Is that right ? Or should I put this .htaccess (also ?) in /home/mydomain/public_html directory ? Thanks again !
    0
  • SysSachin
    You will have to use following code in your /home/mydomain/public_html directory and same code in your subdomain directory (/home/mydomain/subdomain.mydomain.com/), Just change your domain name to sub-domain.
    RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]
    0
  • trucmuche
    Thank you very much !! :-)
    0
  • cPanelMichael
    Hello, I'm happy to see the provided information was helpful. Let us know if you have any additional questions. Thank you.
    0

Please sign in to leave a comment.