服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

云服务器|WEB服务器|FTP服务器|邮件服务器|虚拟主机|服务器安全|DNS服务器|服务器知识|Nginx|IIS|Tomcat|

服务器之家 - 服务器技术 - WEB服务器 - apache设置自动将http跳转到https的方法

apache设置自动将http跳转到https的方法

2021-09-27 15:07服务器技术网 WEB服务器

客户中心启用了https的ssl证书,现在需要将原先的http直接跳转到https上。这里为大家提供一个我经常使用到的方法,即使用伪静态功能

复制代码 代码如下:

<Directory "/opt/fivetrees">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride All #这里原先是None要改为All
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>

 

首先,在网站根目录下创建.htaccess文件,在最下面添加写入如下语句:

 

复制代码 代码如下:

RewriteEngine on
RewriteBase / #我这行是没有配置
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

延伸 · 阅读

精彩推荐