经过多次尝试,我仍然无法正确地从非https或非www重定向到带有www的https。我希望这里有人可以帮助我。我将解释到目前为止我有什么(正在运行):
我的主文件mysite.conf位于站点可用的目录中(Ubuntu 18.04上的Apache2)。
<VirtualHost *:80>
ServerName mysite.nl
ServerAlias www.mysite.nl
DocumentRoot /var/www/mysite.nl
ServerAdmin info@mysite.nl
<Directory /var/www/mysite.nl>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<FilesMatch ".php$">
SetHandler "proxy:unix:/var/run/php/php7.3-fpm.sock|fcgi://localhost/"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
#RewriteCond %{SERVER_NAME} =mysite.nl
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Redirect permanent / https://www.mysite.nl/
</VirtualHost>
我的Certbot制作了一个新文件,该文件将用于HTTPS。该文件写在下面:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName mysite.nl
ServerAlias www.mysite.nl
DocumentRoot /var/www/mysite.nl
ServerAdmin info@mysite.nl
<Directory /var/www/mysite.nl>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<FilesMatch ".php$">
SetHandler "proxy:unix:/var/run/php/php7.3-fpm.sock|fcgi://localhost/"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteCond %{SERVER_NAME} =mysite.nl
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
#Redirect permanent / https://www.mysite.nl
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/www.mysite.nl/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.mysite.nl/privkey.pem
</VirtualHost>
</IfModule>
我现在遇到的问题是,我始终希望用户以https://www.mysite.nl/结尾 因此,在任何其他情况下,例如:
我希望将用户重定向到https://www.mysite.nl/。
由于过去两天的尝试都以失败告终,我希望有人能帮助我解决该问题。