apache - 将子域 A 重定向到 https 域 B

标签 apache ssl redirect

我尝试寻找与我的问题相关的帖子,但找不到合适的帖子。如果有,请告诉我!

这是我现在面临的现状。我想重定向一个域,

example.hr

正在与另一台服务器一起使用,并且它附带了一个 SSL。

现在,我有另一台服务器自带的域,

example.co

还有 SSL 证书。

我想将 test.example.hr 重定向到 https://example.co .我该怎么做呢?我正在使用子域对其进行测试,因为根域已被使用。

这个方法我试过了,

<VirtualHost *:80>
        ServerName test.example.hr
        ServerAlias www.test.example.hr
        Redirect / https://example.co/
</VirtualHost>


<VirtualHost *:443>
    ServerName example.co
    ServerAlias www.example.co
    DocumentRoot /var/www/html
    ErrorLog /var/www/html/error.log
    CustomLog /var/www/html/access.log combined
</VirtualHost>

SSL 配置在 443 block 内。

当我转到 test.example.hr 时,它将变为 https://test.example.hr并且出现的错误是“您的连接不是私密的。攻击者可能试图从 test.alt.hr 窃取您的信息(例如,密码、消息或信用卡)。了解更多 NET::ERR_CERT_COMMON_NAME_INVALID"

最佳答案

你能试试这个并更新我吗。

<VirtualHost *:80>
        ServerName test.example.hr
        ServerAlias www.test.example.hr
        Redirect / http://example.co/

        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
        </VirtualHost>


<VirtualHost *:443>
    ServerName example.co
    ServerAlias www.example.co
    DocumentRoot /var/www/html
    ErrorLog /var/www/html/error.log
    CustomLog /var/www/html/access.log combined
</VirtualHost>

确保启用a2enmod rewrite

关于apache - 将子域 A 重定向到 https 域 B,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49425279/

相关文章:

django - 带有 django 和 mod_wsgi 的基于 SSL 的虚拟主机

apache - 单个用户下的多个域的目录结构应该是什么? ( Apache )

ssl - 本地主机和主机上的 cookie

.htaccess - 从查询字符串中删除字符

redirect - Drupal 7 一些不存在的 URL 不会重定向到 404?

ruby-on-rails - Rails "please wait"页面

apache - 关闭由 QNetworkAccessManager 处理的连接

php - 在 PHP 中构建更直观的聊天过滤器

tomcat - GKR 存储类型在 tomcat 中不起作用

amazon-web-services - 使用 AWS (ec2) 主机激活 PositiveSSL - Namecheap