Arama Yap Mesaj Submit
Request a Callback
+90
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro

Contact Us

Location Halkali merkez neighborhood fatih st ozgur apt no 46 , Kucukcekmece , Istanbul , 34303 , TR
Apache Access Control

How to Block Sensitive Files and IP Addresses with `.htaccess`

Apache 2.4 access control uses `Require` directive. Sensitive files, backups, and upload folder executable extensions can be selectively blocked; IP allowlist should not be applied without proper configuration of real client IP behind reverse proxy/Cloudflare

Require all deniedFilesMatchIP Allowlist.env403
Apache/LiteSpeed Diagnostics
403 Forbidden
Require all denied
client denied by server configuration
AH01630: client denied
Directory index forbidden
01Verify file and document root
02Take a backup and read the error log
03Separate server and application context
04Verify live result with curl
01
Safe technical approach

Blocking File, Directory, and IP Access How to analyze?

Apache 2.4 access control uses `Require` directive. Sensitive files, backups, and upload folder executable extensions can be selectively blocked; IP allowlist should not be applied without proper configuration of real client IP behind reverse proxy/Cloudflare

01

Determine server type

Do not expect a `.htaccess` result without reserving the Apache, LiteSpeed, Plesk proxy or NGINX-only structure.

02

Get backup and logs

Back up the current file with the date; Find the directive and line in the Apache/LiteSpeed error log.

03

Change one rule

Do not change redirect, rewrite, header and access rules all at the same time.

04

Test from outside

Measure the status, Location, Content-Type and redirect number with curl and check the cache layers separately.

Do not use unconditional `Require all denied` at the site root.

02
Live problem dictionary

Apache, redirect and access messages

01kritik

.env or can be downloaded

Meaning: The sensitive configuration file is accessible over the web.

Possible cause: No access rules present or the server is NGINX-only.

02kritik

PHP is running inside uploads

Meaning: The uploaded malicious file is executable.

Possible cause: Script execution is enabled in the upload directory.

03warning

Require all denied shut down the entire site

Meaning: The rule is in the wrong directory or uses a broad FilesMatch.

Possible cause: Scope error.

04warning

IP allowlist is blocking everyone

Meaning: Apache sees proxy IP.

Possible cause: No mod_remoteip or trusted proxy configuration.

05warning

403 only behind Cloudflare

Meaning: The origin access rule is incompatible with Cloudflare IPs.

Possible cause: The remote IP is incorrect.

06warning

Options -Indexes causes 500

Meaning: Options override permission is disabled.

Possible cause: AllowOverride Options yok.

07warning

Apache 2.2 rule ineffective/incompatible

Meaning: Order/Deny/Allow old syntax.

Possible cause: Apache 2.4 migration.

08bilgi

403 expected security result

Meaning: The protected file is successfully blocked.

Possible cause: Require/FilesMatch matched.

No records matching this expression were found.

03
Copiable controls

curl, Apache log and file tests

Sensitive File URL Test

for p in .env .git/config backup.zip database.sql error.log; do curl -sS -o /dev/null -w "$p %{http_code}\n" "https://example.com/$p"; done

Checks the HTTP status of common sensitive files.

Directory listing test

curl -sL https://example.com/uploads/ | head -n 30

Shows whether a directory listing is displayed for a directory without an index file.

PHP upload scan

find uploads -type f \( -iname '*.php' -o -iname '*.phtml' -o -iname '*.phar' -o -iname '*.php*' \) -print

Lists executable PHP-like files in the upload directory.

Access rules

grep -RniE 'Require|FilesMatch|Files>|Options -Indexes|Order|Deny|Allow' . --include='.htaccess' | head -n 120

Finds all subdirectory access rules.

Real client IP headers

curl -sSI https://example.com/ip-test | grep -iE '^server:|^cf-connecting-ip:|^x-forwarded-for:|^x-real-ip:'

Checks proxy/CDN markers; the origin application needs to be logged separately.

Apache access log

tail -n 100 /var/log/apache2/access.log 2>/dev/null || tail -n 100 /usr/local/apache/domlogs/example.com 2>/dev/null || tail -n 100 /var/log/httpd/access_log

403 and client IP records are displayed.

04
Correct and incorrect structure

.htaccess rule comparisons

Sensitive extensions

Risky / Incorrect
<FilesMatch ".*">
Require all denied
</FilesMatch>
Right Approach
<FilesMatch "(?i)^(?:\.env|\.git|.*\.(?:sql|log|bak|ini|zip))$">
Require all denied
</FilesMatch>

Upload PHP engeli

Risky / Incorrect
Require all denied
Right Approach
<FilesMatch "(?i)\.(?:php[0-9]?|phtml|phar)$">
Require all denied
</FilesMatch>

Admin IP allowlist

Risky / Incorrect
Require ip %{HTTP:X-Forwarded-For}
Right Approach
<RequireAny>
Require ip 203.0.113.10
Require ip 198.51.100.0/24
</RequireAny>

Dizin listeleme

Risky / Incorrect
IndexIgnore *
Right Approach
Options -Indexes
05
Application by infrastructure

Apache, cPanel, Plesk, LiteSpeed and applications

Apache / LiteSpeed

FilesMatch, Require, and Options directives work with the appropriate AllowOverride class.

  • Move the sensitive file outside the web root as a priority.
  • Test FilesMatch regex in staging.
  • Monitor 403 logs.

Cloudflare / Reverse Proxy

IP rules may see the proxy IP instead of the real client IP.

  • Configure mod_remoteip/trusted proxy at the server level.
  • Do not blindly trust a header value inside `.htaccess`.
  • You can also restrict origin access to Cloudflare IPs.

WordPress / WISECP / Uploads

Config, log, backup, and upload directories should be protected without disrupting application access

  • Test the URL access to wp-config and WISECP config files.
  • Disable PHP execution inside the uploads directory.
  • Check the requirements of update and backup plugins.
Incorrect interventions

Absolutely don't

  • Do not use unconditional `Require all denied` at the site root.
  • Do not perform IP authorization without validating the X-Forwarded-For header.
  • Do not rely solely on `.htaccess` rules and leave sensitive backups in the web root.
  • Do not just change the extension of suspicious files in the upload directory without examining them.
Post-procedure check

Verify the solution

  • Sensitive URLs return 403/404 and normal static files return 200.
  • No executable PHP-like files exist in the upload directory.
  • The IP allowlist works correctly with the real client IP.
  • The application continues to access config/log files through the filesystem.
06
Internal SEO content set

Related .htaccess solutions

07
primary sources

Apache, WordPress and panel documentation

08
Frequently asked questions

Blocking File, Directory, and IP Access Curiosities about

Does the file, directory, and IP access blocking rule work on NGINX?

No. NGINX does not read `.htaccess` files. The rule must be translated to a `server` or `location` configuration.

Is Apache restart required for .htaccess changes?

Usually not; Apache evaluates the `.htaccess` file on each request. However, a reload or restart is required for VirtualHost, module, or AllowOverride changes.

What should be done before editing the file?

A dated backup of the existing file should be taken, the active document root verified, and the change tested on staging or during low-traffic periods.

Where is the file located in Plesk with cPanel?

In cPanel it is usually inside `public_html`, in Plesk inside `httpdocs`; addon domains and subdomains may have a different document root.

Does LiteSpeed support `.htaccess` rules?

LiteSpeed supports most rules through Apache compatibility; some module and handler behaviors may differ.

Where should I look first in case of a 500 error?

Full directive and line record in Apache/LiteSpeed error log. The file should be restored according to the log instead of being deleted randomly.

Can these codes be added directly to the live site?

Domain should not be added directly without verifying domain, document root, proxy, WordPress, and server structure. Examples should be adapted and tested.

EKA SOFTWARE AND INFORMATION SYSTEMS

Let's edit .htaccess and Apache rules without making the site inaccessible

We examine redirection, rewrite, CORS, access and 500 errors with logs in cPanel, Plesk, LiteSpeed, WordPress, custom PHP and WISECP structures.

Get Server SupportWhatsApp
Top