apache web server

How to Restrict Access to Specific Files in .htaccess

This article introduces how to restrict access to specific files in .htaccess on Apache servers. I wanted to display only PHP files and not display txt files. You can restrict access to specific files by specifying the path from the current directory using regular expressions.

Shou Arisaka
1 min read
Oct 25, 2025

This article introduces how to restrict access to specific files in .htaccess on Apache servers.

I wanted to display only PHP files and not display txt files. You can restrict access to specific files by specifying the path from the current directory using regular expressions.

RewriteRule ^.*\.txt$ - [F,L]

Share this article

Shou Arisaka Oct 25, 2025

๐Ÿ”— Copy Links