我的情况如下:我有两个 CNAME 域(domain.one.com
和domain.two.com
),它们指向同一个 IP / 机器,我想将其中一个重定向到另一个,比如domain.one.com/anything
。domain.two.com/anything
如果domain.two.com
重要的话,有一个有效的 SSL 证书。
我有以下设置:
在httpd.conf
:
RewriteCond %{HTTP_HOST} ^domain\.two\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) https://domain.two.com/$1 [L,R]
NameVirtualHost *:80
NameVirtualHost domain.two.com:443
<VirtualHost *:80>
ServerName domain.two.com
DocumentRoot "/var/www/html/"
ErrorLog logs/error_log
CustomLog logs/access_log common
RewriteEngine On
RewriteOptions Inherit
</VirtualHost>
在ssl.conf
:
<VirtualHost domain.two.com:443>
DocumentRoot "/var/www/html"
ServerName domain.two.com:443
</VirtualHost>
--
到目前为止我已经尝试过:
添加httpd.conf
以下内容:
NameVirtualHost domain.one.com:443
<VirtualHost domain.one.com:80>
ServerName domain.one.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.one.com$
RewriteRule (.*) http://domain.two.com/$1 [R=Permanent]
</VirtualHost>
- 不重定向。
还添加以下内容ssl.conf
:
<VirtualHost domain.one.com:443>
ServerName domain.one.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.one.com$
RewriteRule (.*) http://domain.two.com/$1 [R=Permanent]
</VirtualHost>
- 服务器停止工作。
我知道我做错了什么,但我不知道是什么。我该如何做?
(我应该说一下,在这些事情上我是新手。)
答案1
我建议您在 DNS 设置中使用 A 记录而不是 CNAME 来简化流程。请参阅A、CNAME、ALIAS 和 URL 记录之间的区别
遵循 vhost 配置将满足您的要求。
1)HTTPdomain.one.com 至HTTPS域名.two.com
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
ServerName domain.one.com
RewriteEngine On
RewriteRule ^(.*)$ "https://domain.two.com$1" [R,L]
ErrorLog logs/error_log
CustomLog logs/access_log common
DocumentRoot "/var/www/html/"
<Directory "/var/www/html/">
Require all granted
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName domain.two.com
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/your.crt
SSLCertificateKeyFile /etc/apache2/ssl/your.key
SSLCertificateChainFile /etc/apache2/ssl/chain.crt
ErrorLog logs/error_log
CustomLog logs/access_log common
DocumentRoot "/var/www/html/"
<Directory "/var/www/html/">
Require all granted
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
2)两者皆可HTTP和HTTPSdomain.one.com 至HTTPS域名.two.com
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
ServerName domain.one.com
RewriteEngine On
RewriteRule ^(.*)$ "https://domain.two.com$1" [R,L]
ErrorLog logs/error_log
CustomLog logs/access_log common
DocumentRoot "/var/www/html/"
<Directory "/var/www/html/">
Require all granted
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName domain.one.com
RewriteEngine On
RewriteRule ^(.*)$ "https://domain.two.com$1" [R,L]
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/your.crt
SSLCertificateKeyFile /etc/apache2/ssl/your.key
SSLCertificateChainFile /etc/apache2/ssl/chain.crt
ErrorLog logs/error_log
CustomLog logs/access_log common
DocumentRoot "/var/www/html/"
<Directory "/var/www/html/">
Require all granted
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName domain.two.com
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/your.crt
SSLCertificateKeyFile /etc/apache2/ssl/your.key
SSLCertificateChainFile /etc/apache2/ssl/chain.crt
ErrorLog logs/error_log
CustomLog logs/access_log common
DocumentRoot "/var/www/html/"
<Directory "/var/www/html/">
Require all granted
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>