我希望 Apache 上的域名纯粹作为重定向存在。为此,我创建了/etc/apache2/sites-available/redirect.example.info.conf
以下内容:
<VirtualHost *:80>
ServerName redirect.example.info
ServerAdmin webmaster@localhost
Redirect / https://example.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
当我运行的时候certbot --apache
,它被重写为:
<VirtualHost *:80>
ServerName redirect.example.info
ServerAdmin webmaster@localhost
Redirect / https://example.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =redirect.example.info
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
/etc/apache2/sites-available/redirect.example.info-le-ssl.conf
并创建一个新文件:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName redirect.example.info
ServerAdmin webmaster@localhost
Redirect / https://example.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/ca-webs.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/ca-webs.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
这确实按预期工作。重定向运行http://redirect.example.info
→ https://redirect.example.info
→ https://example.com
。但我不清楚它是如何工作的。重写的文件既有Redirect
命令,又有RewriteRule
命令,我本以为Redirect
(先来)会优先。这个文件实际上是如何评估的?