apache主机使用htaccess自动跳转http到https

在主机根目录.htaccess文件内,添加如下内容:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

解释一下,将所有http访问请求,跳转到https访问。

如果你的主机根目录已有.htaccess文件,不必重复写RewriteEngine On这一行内容,只需要把下面两行的内容添加到下面即可。

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.