after many attempts I am still unable to redirect properly from non https or non www to https with www. I hope someone here can help me out. I'll explain what I have so far (which is working):
I have my main file mysite.conf in my sites-available directory (Apache2 on Ubuntu 18.04).
Code:
<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>
My Certbot made a new file which will be used for HTTPS. The file is written below:
Code:
<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>
The problem I am having now is that I always want the user to end up at https://www.mysite.nl/
So in any other case for example:
- www.mysite.nl
- http://mysite.nl
- https://mysite.nl
- http://www.mysite.nl
I want the user to be redirected to https://www.mysite.nl/.
I hope someone can help me out on how to fix this as I have failed on any attempt that I made the last two days.
Bookmarks