HTTP to HTTPS automatic redirection

I’ve successfully installed “Let’s Encrypt” on my website. It works fine, but when someone tries to visit my website and not type “https” in the beginning, it’ll load the “http” URL.

My question is: How to redirect all “http” URLs to “https”?


You need to add a rewrite rule

  1. If its apache you can add it via .htaccess or web config
    RewriteEngine on
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [NC,R=301,L]
  2. If its Nginx , add it in your config
    rewrite ^ (.*) https://$host$request_uri? permanent;
    // note : $host/$server_name
    return 301 https://$server_name$request_uri;
1 Like

Ok. So the only thing I need is to change values of RewriteEngine, RewriteCond and RewriteRule and instead of SERVER_PORT and SERVER_NAME write my own concrete port and name. Is that so?

Those are internal variables, so you don’t need to change them.

copy paste it . it will work.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.