简体   繁体   English

使用https重写Apache 2.4网址

[英]Apache 2.4 url rewriting with https

I'm trying to do an url rewriting with Apache 2.4. 我正在尝试用Apache 2.4重写URL。 I want that requests to 我希望该请求

  1. http://subdomain.domain.com http://subdomain.domain.com
  2. http://www.subdomain.domain.com http://www.subdomain.domain.com
  3. https://www.subdomain.domain.com https://www.subdomain.domain.com

are remapped to 重新映射到

https://subdomain.domain.com https://subdomain.domain.com

to avoid an error in SSL wildcard cert that doesn't not match www.subdomain.domain.com. 为避免SSL通配符证书中的错误与www.subdomain.domain.com不匹配。

I tried with: 我尝试过:

    <VirtualHost ip:80>
        ServerName subdomain.domain.com
        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}       
   </VirtualHost>
   <VirtualHost ip:80>
        ServerName www.subdomain.domain.com
        Redirect permanent / https://subdomain.domain.com
   </VirtualHost>
   <VirtualHost ip:443>
        ServerName www.subdomain.domain.com
        Redirect permanent / https://subdomain.domain.com
   </VirtualHost>
  <VirtualHost ip:443>
        ServerName subdomain.domain.com
        ...
        ...
        ...

My configuration works for (1) and (2) but not for (3). 我的配置适用于(1)和(2),但不适用于(3)。 Where is my mistake? 我的错误在哪里?

I think the problem is that one of your port 443 virtualhosts does not have SSL on. 我认为问题在于您的端口443虚拟主机之一没有启用SSL。

Try this 尝试这个

<VirtualHost ip:443>
    ServerName www.subdomain.domain.com
    Redirect permanent / https://subdomain.domain.com
    SSLEngine on
    SSLCertificateFile    /something
    SSLCertificateKeyFile /something
</VirtualHost>

Otherwise, the request simply won't be understood, because it's encrypted. 否则,由于该请求已加密,因此根本无法理解该请求。

See eg How to redirect https to http without any SSL Certificate for why this is necessary. 请参阅例如如何在没有任何SSL证书的情况下将https重定向到http,以了解为什么这样做是必要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM