.htaccess 将非 SSL 域重定向到另一个 SSL 域
.htaccess redirecting non SSL Domain to another SSL Domain
我有以下.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.old_domain.de$
RewriteRule (.*) https://new_domain.de/ [R=301,L]
问题是,该规则似乎只重定向 www.old_domain.de 或 http://www.old_domain.de correctly, but does not redirect https://old_domain.de 或 old_domain.de(自动跳转到 https://)。在第二种情况下,出现以下错误:
SSL_ERROR_UNRECOGNIZED_NAME_ALERT
我已经尝试将 https:// 和非 www 域重写为 http://www。但无法以某种方式达到预期的结果。可能我在这里漏掉了一些重要的东西。
我的新域的 .htaccess 中的 https:// 强制是否有问题?
重定向 http://www.old_domain.de or www.old_domain.de or http://old_domain.de 或 old_domain.de 使用下面的代码
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?old_domain\.de$ [NC]
RewriteRule (.*) https://new_domain.de/ [R=301,L]
您的代码在 RewriteCond 中缺少 (www\.)?
,这将使重写工作,无论它是否包含 www。
您可以在 link
使用 htaccess 测试器测试相同内容
同样,您应该为 SSL (HTTPS) 配置一个单独的虚拟主机。在该虚拟主机中,您还需要复制上面的代码。
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>
如果您仍然找不到配置虚拟主机侦听 443 的文件,您可以 运行 使用 -S 标志 的 apache,如下面的命令
httpd -S or apachectl -S
这将为您提供监听 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)
例如/etc/httpd/conf.d/ssl.conf
就是配置虚拟主机监听443的文件
我有以下.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.old_domain.de$
RewriteRule (.*) https://new_domain.de/ [R=301,L]
问题是,该规则似乎只重定向 www.old_domain.de 或 http://www.old_domain.de correctly, but does not redirect https://old_domain.de 或 old_domain.de(自动跳转到 https://)。在第二种情况下,出现以下错误:
SSL_ERROR_UNRECOGNIZED_NAME_ALERT
我已经尝试将 https:// 和非 www 域重写为 http://www。但无法以某种方式达到预期的结果。可能我在这里漏掉了一些重要的东西。
我的新域的 .htaccess 中的 https:// 强制是否有问题?
重定向 http://www.old_domain.de or www.old_domain.de or http://old_domain.de 或 old_domain.de 使用下面的代码
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?old_domain\.de$ [NC]
RewriteRule (.*) https://new_domain.de/ [R=301,L]
您的代码在 RewriteCond 中缺少 (www\.)?
,这将使重写工作,无论它是否包含 www。
您可以在 link
使用 htaccess 测试器测试相同内容同样,您应该为 SSL (HTTPS) 配置一个单独的虚拟主机。在该虚拟主机中,您还需要复制上面的代码。
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>
如果您仍然找不到配置虚拟主机侦听 443 的文件,您可以 运行 使用 -S 标志 的 apache,如下面的命令
httpd -S or apachectl -S
这将为您提供监听 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)
例如/etc/httpd/conf.d/ssl.conf
就是配置虚拟主机监听443的文件