Allowing to access files in hidden directories on Apache server (especially ".well-known" folder)

jack1142 picture jack1142 · May 13, 2018 · Viewed 7.5k times · Source

I want to create SSL certificate for my domain via the webroot directory ".well-known/acme-challenge" for verification. I'm using shared hosting and I don't have access to apache configuration files, so I can only use .htaccess file.

Problem is that I can't access files in this folder from browser using address "my.domain/.well-known/acme-challenge/filename". I'm just getting 404 error, even though I have these files in this directory.

So I want to know, if there's any rule, which I could use in .htaccess file to gain access to hidden directories from browser. If you need more informations let me know.

Answer

danielh picture danielh · May 13, 2018

Assuming your host allows overrides, this may work:

    <IfModule mod_rewrite.c> 
        RewriteCond %{REQUEST_FILENAME} !.well-known/
        RewriteRule "(^|/)\.(?!well-known)" - [F]
    </IfModule>