Search code examples
apache.htaccesshttp-status-code-404hidden-files

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


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.


Solution

  • Assuming your host allows overrides, this may work:

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