HTTP to HTTPS automatic redirection


#1

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”?

Thanks!


#2

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
    or
    return 301 https://$server_name$request_uri;

#3

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?


#4

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


#5

copy paste it . it will work.


#6

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