简体   繁体   中英

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

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]

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM