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

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

问题描述

环境 Centos with apache

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

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

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