
所以過去我用過https://example.com。然後決定我想使用https://myotherexample.com而不是 example.com。所以我設定了伺服器,將 DNS 指向該伺服器,一切都很好。現在我想重定向https://example.com到https://myotherexample.com因此使用舊地址的人將繼續訪問新網站。這對於將連接埠 80 重定向到新網域來說效果很好,但是當嘗試重定向連接埠 443(ssl 連接埠)時,apache 似乎需要舊網域有一個有效的 SSL 憑證(即使我不再提供安全版本)該地址的站點)。我的舊網域 SSL 憑證已過期,由於沒有任何內容可以保護,我想知道如何進行這種重定向?
example.com 配置:
▽
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /sites/example.com/html
ServerName example.com
ServerAlias www.example.com
Redirect / https://myotherexample.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
以及我需要重新導向到新網域的 SSL 版本:
<VirtualHost *:443>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /sites/example.com/html
ServerName example.com
ServerAlias www.example.com
Redirect / https://myotherexample.com/
<Directory /sites/example.com/html>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
SSLEngine on
SSLCertificateKeyFile /etc/apache2/ssl/example.com.key
# this ssl is expired now
SSLCertificateFile /etc/apache2/ssl/example.com.crt
SSLCertificateChainFile /etc/apache2/ssl/example.com.IntermediateCA.crt
</VirtualHost>
顯然我的做法是錯誤的,但是有沒有辦法使用 apache 將 SSL 網域(網域的 https 版本)重新導向到新網域,而不需要在舊網域上保留活動的 ssl 憑證?非常感謝!
答案1
這是您所期望的行為。想像一下,如果有人劫持了您的 DNS 並設定了 301 重定向。您可以使用https://letscrypt.org/取得免費憑證並重新導向客戶端,直到不再造訪舊網域。
答案2
我贊成馬特的回复,但我想更明確地說明這一點。
重定向是一個 HTTP 事物,以一組回應狀態代碼 (3XX) 和一個特定標頭(位置)的形式實現。這是一個普通的 HTTP 事務。成功建立 TLS 連線後,HTTPS 中的 HTTP 才可以使用,而 TLS 需要有效的憑證。因此,沒有有效憑證 => 沒有 TLS => 沒有 HTTPS => 無法重新導向。
過期的憑證無效,因此在更換憑證之前無法執行任何 HTTP 式操作,包括重定向。