要将Apache虚拟主机的HTTP和HTTPS重定向到另一个域名,可以使用以下方法:
ServerName old-domain.com
Redirect permanent / http://new-domain.com/
ServerName old-domain.com
Redirect permanent / https://new-domain.com/
ServerName old-domain.com
RewriteEngine On
RewriteRule ^(.*)$ https://new-domain.com/$1 [R=301,L]
ServerName old-domain.com
SSLEngine on
SSLCertificateFile /path/to/certificate.crt
SSLCertificateKeyFile /path/to/private.key
SSLCertificateChainFile /path/to/chain.crt
RewriteEngine On
RewriteRule ^(.*)$ https://new-domain.com/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain\.com$ [NC]
RewriteRule ^(.*)$ http://new-domain.com/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain\.com$ [NC]
RewriteRule ^(.*)$ https://new-domain.com/$1 [R=301,L]
以上代码示例中,old-domain.com是原始域名,new-domain.com是要重定向到的新域名。请根据实际情况进行相应的更改。另外,如果使用了SSL证书,请确保正确配置了SSL模块和证书路径。
下一篇:Apache虚拟主机基本配置