Http is popular protocol used to transfer web page data like HTML, Javascript, Image etc. HTTP is used between our browser like Chrome, Firefox, Edge, Internet Explorer and server like Apache, Nginx etc. HTTPS is secure version of HTTP and recently sites transition to the HTTPS. But what is a user try to access HTTP of our web site. We can redirect HTTP web sites to the HTTPS. Below you can find redirect ways for different web servers.
Apache
Apache is very popular web server which is number 1 in internet. We can use HTTP 301 Redirect status code for this like below. But as we can see we need to enable RewriteEngine
too.
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Nginx
Nginx is another popular web server which gains momentum in last years. We can use following server
configuration in order to redirect HTTP to HTTPS. We will use HTTP 301 Redirect status code with return
option. Other part of the configuration is just example.
server { listen 80 default_server; listen [::]:80 default_server; server_name _; return 301 https://$host$request_uri; }