Reputation: 251
I’ve looked thru all similar topics around the web, I can’t seem to find the solution.
I have installed the Let’s Encrypt certificate successfully, but I can’t get auto-redirect from http to work. Redirect is set by certbot (Letsencrypt installation script) via /etc/apache2/sites-available/domain.com.conf file. Here is the contents of the file:
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
ServerAdmin webmaster@localhost
DocumentRoot /home/username/public_html/domain.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.domain.com [OR]
RewriteCond %{SERVER_NAME} =domain.com
RewriteCond %{THE_REQUEST} !/(robots.txt|sitemap.xml)\s [NC]
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
The file is linked to its sites-enabled symlink correctly. I tried to reload/restart apache2 service, tried disabling the local .htaccess file for this website, but all to no avail. I scanned thru all the .conf files and made sure this domain is not mentioned in any other .conf file. The weird thing is, redirect does work with some of my websites located on the same server, but with some, it does not.
I’ve tried looking thru the log files, but haven’t found anything specific.
Please help!
Upvotes: 4
Views: 7218
Reputation: 251
Found it.
The reason was that I moved some of the domains from another server, so I copied all the .conf files from there. Because the IP was different, I had to reissue and reinstall the certificates. For some twised reason, Certbot created a <VirtualHost *:80>
section inside every *-le-ssl.conf, but commented out the redirect section. So, instead of domain.com.conf file, a domain.com-le-ssl.conf file was actually used for port 80 connection.
The solution is either to uncomment the redirect section of the *-le-ssl.conf file, or remove <VirtualHost *:80>
part completely from it, to allow the *.conf file to take over.
Upvotes: 7