.htaccess: Why I can't restrict access to certain file extensions?

308 views Asked by At

I've tried a couple of solutions and for some reason, I can't restrict access to files with specific extensions. I use Wordpress and I want to restrict access to all OTF/TTF/WOFF/WOFF2 files that are uploaded in wp-content/uploads/2022/month_name folders (basically, I'd like to restrict access to whole /uploads/ folder with all subfolders). It's on Apache 2.4/PHP 8.0.

I tried this and it doesn't work:

<FilesMatch "\.(otf|ttf|woff|woff2)$">
Order Deny,Allow
   Allow from all
</FilesMatch>

And this one:

RedirectMatch 403 ^wp-content/uploads/2022/11/.+\.(otf|ttf|woff|woff2)$ [F,L,NC]
RedirectMatch 403 ^wp-content/uploads/2022/10/.+\.(otf|ttf|woff|woff2)$ [F,L,NC]
1

There are 1 answers

0
Vijay Hardaha On

Allow from all is wrong, it will allow those files with specified extensions. You need to use Deny from all to restrict access.

So the correct code will be this:

<FilesMatch "\.(otf|ttf|woff|woff2)$">
    Order Deny,Allow
    Deny from all
</FilesMatch>