linux - 如何在 Apache 服务器上自动将 HTTP 重定向到 HTTPS?

环境 Centos 和 apache

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

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

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

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

有什么想法吗?

最佳答案

我实际上已经遵循了这个例子,它对我有用:)

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 重启

https://stackoverflow.com/questions/16200501/

相关文章:

python - 我可以单独使用 Flask app.run() 为多个客户端提供服务吗?

python - 如何在 Python 中直接获取字典键作为变量(而不是通过从值中搜索)?

linux - 如何打印 ld(linker) 搜索路径

python - 如何编写好的/正确的包 __init__.py 文件

c - 在 Linux 中测量时间 - 时间 vs 时钟 vs getrusage vs clock

python - 从 django 的查询集中获取第一个对象的最快方法?

c - 写入 .txt 文件?

python - Argparse:在 "optional arguments"下列出的必需参数?

c - 使用 gcc 命令行从 .c 文件构建 .so 文件

linux - 在 bash 中创建临时文件