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.
Http是流行的协议,用于传输HTML,Javascript,Image等网页数据。HTTP用于我们的浏览器(例如Chrome,Firefox,Edge,Internet Explorer和服务器,例如Apache,Nginx等)之间。HTTPS是HTTP和最近站点的安全版本过渡到HTTPS。 但是,什么是用户尝试访问我们网站的HTTP。 我们可以将HTTP网站重定向到HTTPS。 在下面,您可以找到用于不同Web服务器的重定向方式。
阿帕奇 (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.
Apache是非常流行的Web服务器,在互联网上排名第一。 我们可以像下面这样使用HTTP 301重定向状态代码。 但是正如我们看到的,我们也需要启用RewriteEngine
。
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Nginx的 (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.
Nginx是另一种流行的Web服务器,近年来发展势头强劲。 我们可以使用以下server
配置来将HTTP重定向到HTTPS。 我们将使用带有return
选项的HTTP 301重定向状态代码。 配置的其他部分仅是示例。
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
翻译自: https://www.poftut.com/how-to-redirect-http-to-https-in-apache-nginx/