Force Https CentOS Web Panel

5,624

I have found out that using the .htaccess is the easiest method to solve the problem.

Adding the below mentioned codes in .htaccess gives the solution:

RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://www.yourdomain.com%{REQUEST_URI} [NS,R,L]

If there is any other easiest method than .htaccess redirection exists anyone could help edit this answer.

Share:
5,624
PaladiN
Author by

PaladiN

Updated on September 18, 2022

Comments

  • PaladiN
    PaladiN over 1 year

    I am using CentOS Web Panel and trying to redirect to https also when someone hits the http link. I am only able to open both https when i type https://domain.com.

    Using the below rules solves my problem

    RewriteEngine On
    RewriteCond %{SERVER_PORT} !=443
    RewriteRule ^ https://www.yourdomain.com%{REQUEST_URI} [NS,R,L]
    

    But i need to add this to all the sites in my server.

    How can i automatically redirect all the sites in my server?

    Does any method other than .htaccess redirection exists to redirect to https?

    Hope i have clearly stated the problem.

    • Admin
      Admin over 7 years
      In order to do that you need to add the rule directly to the apache config file and not in .htaccess where it will be more global and not directory specific. You will also need to use the HTTP_HOST var instead of the domain name if you want it to work for other sites.