I am trying to roll my own vhost config to handle certbot/letsencrypt. I want to redirect anything other than requests to /.well-known to HTTPS. But the exception for .well-known is not working; requests for http://www.example.com/.well-known/ return a 301 redirect to https. I have anonimized the hostname in the code below.
Note that I came across this post/answer before posting here - and the accepted answer there describes (I believe) the first of the configurations I have tried below - which makes me think this is not a duplicate.
<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName www.example.com
RewriteEngine on
RewriteCond %{HTTPS} !=on
# RewriteRule ^(\.well-known) - [END]
RewriteCond %{REQUEST_URI} !^\.well-known
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
# additional auth config elsewhere, hence....
<Location /.well-known/ >
Require all granted
</Location>
</VirtualHost>
As indicated by the commented line above, I also tried:
RewriteRule ^(\.well-known) - [END]
# RewriteCond %{REQUEST_URI} !^\.well-known
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
There is no .htaccess file on the path, but just to make sure, I disabled all the rewrite instructions and got HTTP 200 responses both for /.well-known/ and other requests. I am testing using curl -I
so browser caching of 301's is not a consideration. After each change I have run a ful restart of httpd, not just a reload.
This is httpd-tools-2.4.6-99 on Centos 7.
How can I override a default redirect?