简体   繁体   English

.htaccess将非SSL域重定向到另一个SSL域

[英].htaccess redirecting non SSL Domain to another SSL Domain

I have the following .htaccess: 我有以下.htaccess文件:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.old_domain.de$
RewriteRule (.*) https://new_domain.de/$1 [R=301,L]

The Problem is, the rule seem to only redirect www.old_domain.de or http://www.old_domain.de correctly, but does not redirect https://old_domain.de or old_domain.de (Which jumps to https:// automaticaly). 问题是,该规则似乎只能正确重定向www.old_domain.de或http://www.old_domain.de ,但不能重定向https://old_domain.de或old_domain.de(这会跳转到https:// automaticaly)。 I the second case I get the following error: 在第二种情况下,我得到以下错误:

SSL_ERROR_UNRECOGNIZED_NAME_ALERT SSL_ERROR_UNRECOGNIZED_NAME_ALERT

I already tried to rewrite https:// and non-www domains into http://www . 我已经尝试将https://和非www域重写为http:// www but wasn't able to achieve the wanted results somehow. 但无法以某种方式获得想要的结果。 Probably I miss something Important here. 我可能在这里错过了重要的事情。

Is it possible there's something wrong with the https:// forcing at the .htaccess of my new domain? 我的新域的.htaccess中的https://强制可能有问题吗?

For redirecting http://www.old_domain.de or www.old_domain.de or http://old_domain.de or old_domain.de use the below code 要重定向http://www.old_domain.de或www.old_domain.de或http://old_domain.de或old_domain.de,请使用以下代码

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?old_domain\.de$ [NC]
RewriteRule (.*) https://new_domain.de/$1 [R=301,L]

Your code is missing the (www\\.)? 您的代码缺少(www\\.)? in RewriteCond which will make the rewrite works irrespective of whether it contains a www or not. 在RewriteCond中,无论重写是否包含www,都将使重写有效。

You can test the same using htaccess tester at link 您可以在链接上使用htaccess测试器测试相同的内容

Similarly you should have a separate virtual host configured for SSL (HTTPS) . 同样,您应该为SSL(HTTPS)配置一个单独的虚拟主机。 In that virtual host you also needs to copy the above code. 在该虚拟主机中,您还需要复制上面的代码。

SSL is configured on port 443 to listen, so search for something similar to below code in your htaccess SSL已在端口443上配置为侦听,因此请在htaccess中搜索类似于以下代码的内容

<VirtualHost *:443>

    ServerName www.old_domain.de
    ServerAlias old_domain.de

    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/example/apache.crt
    SSLCertificateKeyFile /etc/apache2/ssl/example/apache.key 

 </VirtualHost>

If you are still unable to find the file where virtual host listening on 443 is configured you can run the apache with the -S flag like below command 如果仍然找不到在443上侦听虚拟主机的配置文件,则可以使用-S标志运行apache,如下所示:

httpd -S or apachectl -S

This will give you the name of the file where virtual host listening on 443 is configured as in the below output 这将为您提供文件名,其中配置了在443上侦听虚拟主机,如以下输出所示

*:80     default server xxx.xxx.xxx.xxx (/etc/httpd/conf.d/eco.conf:1)
         port 80 namevhost xxx.xxx.xxx.xxx (/etc/httpd/conf.d/eco.conf:1)

*:443    default server xxx.xxx.xxx.xxx (/etc/httpd/conf.d/ssl.conf:1)
         port 443 namevhost xxx.xxx.xxx.xxx (/etc/httpd/conf.d/ssl.conf:1)

For example /etc/httpd/conf.d/ssl.conf is the file in which virtual host listening on 443 is configured. 例如, /etc/httpd/conf.d/ssl.conf是配置了侦听443的虚拟主机的文件。

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

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