Problem with Virtualmin, Letsencrypt and redirect to https in the .htaccess file

5 posts / 0 new
Last post
#1 Sat, 05/05/2018 - 04:17
customsoft
customsoft's picture

Problem with Virtualmin, Letsencrypt and redirect to https in the .htaccess file

Hello guys I have a small problem with Virtualmin, Letsencrypt and redirect to https in the .htaccess file.

I have included in the .htaccess the following rule to redirect sites to https:

RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


The problem is that, I have to comment on this rule when updating Letsencrypt certificates.

Do you have any suggestions to avoid having to manually comment on the rule, keep the redirect at https and let Letsencrypt automatically update the certificate?

Thanks!

Sat, 05/05/2018 - 06:33
Diabolico
Diabolico's picture

Try with this:

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]

Just copy/paste, it will work with any domain.

- I often come to the conclusion that my brain has too many tabs open. -
Failing at desktop publishing & graphic design since 1994.

Sun, 05/06/2018 - 08:29 (Reply to #2)
customsoft
customsoft's picture

Slightly modified but it works! Thank you very much.

Sun, 05/06/2018 - 18:52
noisemarine

I've been using

RedirectMatch ^/(?!.well-known)(.*)$ https://www.example.com/$1

I just paste it at the end of Webmin -> Servers -> Apache Webserver -> Virtual Server on Port 80 -> Edit Directives.

Just as an aside, it would be nice if the FAQ on the LE website listed some of these kinds of tips.

Mon, 05/07/2018 - 13:59
Diabolico
Diabolico's picture

@customsoft: Happy to see it helped with your problem. Could you post your modified solution just in case someone have same problem to be able to test both versions.

- I often come to the conclusion that my brain has too many tabs open. -
Failing at desktop publishing & graphic design since 1994.

Topic locked