如何自动将HTTP重定向到Apache服务器上的HTTPS? [英] How to automatically redirect HTTP to HTTPS on Apache servers?

查看:211
本文介绍了如何自动将HTTP重定向到Apache服务器上的HTTPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境带有Apache的Centos

Environment Centos with apache

尝试设置从http到https的自动重定向

Trying to setup automatic redirection from http to https

From manage.mydomain.com --- To ---> https://manage.mydomain.com 

我尝试将以下内容添加到我的httpd.conf中,但没有成功

I have tried adding the following to my httpd.conf but it didn't work

 RewriteEngine on
    ReWriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]

有什么想法吗?

推荐答案

我实际上已经遵循了这个示例,并且对我有用:)

I have actually followed this example and it worked for me :)

NameVirtualHost *:80
<VirtualHost *:80>
   ServerName mysite.example.com
   Redirect permanent / https://mysite.example.com/
</VirtualHost>

<VirtualHost _default_:443>
   ServerName mysite.example.com
  DocumentRoot /usr/local/apache2/htdocs
  SSLEngine On
 # etc...
</VirtualHost>

然后做:

/etc/init.d/httpd restart

这篇关于如何自动将HTTP重定向到Apache服务器上的HTTPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆