apache服务器配置http自动跳转到https,apache设置自动将http跳转到https的措施

复制代码 代码如下:

第一步

默认情况下,apache的80端口网站目录是/var/www/html
查找配置文件并修改/etc/httpd/conf/httpd.conf
利用伪静态功能
<Directory “/var/www/html”>

1.Apache2.2\conf\httpd.conf中释放:
Include conf/extra/httpd-vhosts.conf(去掉前面的#)
2.httpd.conf中增加
<Directory “E:/work/test”>
#项目文件夹DWM目录,注意不要使用中文定义目录与文件夹
#
# 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
#
# 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 None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
<Directory “C:/phpMyAdmin”> #phpMyAdmin的安装路径
#
#
# 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
#
# 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
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
3.在文件Apache2.2\conf\extra\httpd-vhosts.conf中增加:

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

Possible values for the Options directive are “None”, “All”,

复制代码 代码如下:

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

or any combination of:

<VirtualHost *:80> #放在第一个
ServerAdmin webmaster@dummy-host2.ies.inventec
DocumentRoot “D:\work\test”
ServerName test
ErrorLog “logs/dummy-host2.ies.inventec-error.log”
CustomLog “logs/dummy-host2.ies.inventec-access.log” common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.ies.inventec
DocumentRoot “C:\Program Files\phpMyAdmin-2.11.4”
ServerName mysql
ErrorLog “logs/dummy-host2.ies.inventec-error.log”
CustomLog “logs/dummy-host2.ies.inventec-access.log” common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.ies.inventec
DocumentRoot “C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs”
ServerName localhost
ErrorLog “logs/dummy-host2.ies.inventec-error.log”
CustomLog “logs/dummy-host2.ies.inventec-access.log” common
</VirtualHost>

复制代码 代码如下:

Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

4.在windows\system32\drivers\etc\hosts檔中增加:(是hosts檔,不是hosts.msn之类的)
127.0.0.1 test
127.0.0.1 mysql
5.在浏览器中输入:
//查看数据库设置是否成功
//查看项目路径设置是否成功

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

Note that “MultiViews” must be named explicitly — “Options All”

您可能感兴趣的文章:

  • http自动跳转https的配置方法
  • http转https的实战记录(iis
    7.5)

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

AllowOverride All   #原来是None,需要改成All

Controls who can get stuff from this server.

Order allow,deny
Allow from all

</Directory>

第二步

然后在需要跳转的网站根目录,也就是80端口的网站根目录/var/www/html下创建一个.htaccess文件,如果目录下已经有.htaccess文件,则用vi或者其他编辑器打开,在最下面添加写入如下语句即可
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ [L,R]
保存,重启httpd服务,再次访问
配置成功。

http://blog.csdn.net/luhuisicnu/article/details/50402822

http://www.cnblogs.com/niejunlei/p/5279677.html