Arclin

Advocate Technology. Enjoy Technology.

0%

Apache强制https

当用户访问http的地址的时候,Apache如何强制跳转到https地址

修改httpd.conf

  1. LoadModule rewrite_module modules/mod_rewrite.so 这个拓展貌似是已经被加载了;
  2. 修改Apache默认项目路径的这个
1
<Directory "/var/www/html">

其实是修改为项目发布的路径

1
<Directory "/var/www/html/app/src/htdocs_www">

改为All

1
AllowOverride All
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 
# 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 Indexes 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
#
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

添加三行代码

1
2
3
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]