欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

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

程序员文章站 2023-11-16 09:02:04
复制代码 代码如下:## possible values for the options directi...

复制代码 代码如下:

<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]