example.com 到 https://www.example.com | Apache

example.com 到 https://www.example.com | Apache

所以我想重定向example.comhttps://www.example.com。我已经有带有 certbot 的 ssl,但我想更改中的重定向配置/etc/apache2/sites-available/example.conf

example.comCertbot 已经为您提供了从到 的重定向https://example.com

这是我当前的 apache 配置

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

答案1

推荐配置简单重定向是为了避免重写规则并简单地设置一个重定向指令:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    Redirect permanent "/" " https://www.example.com/" 
</VirtualHost>

相关内容