Q:

How can I pretend 403 page to 404 on apache 2.4?

How can I pretend 403 page to 404 on apache 2.4?
Here is my directory structure, I use codeigniter3.
document_root/
    admin/ <- codeigniter project
        application/
        bin/
        public/
            index.php
        vendor/
        .htaccess <- access restriction write to here.
        composer.json
    index.html <- front page

I want to deny access from uncertified IP addresses.
With return responce code 404, Not 403. (Cuz wanna hide directory exists)
document_root/
    admin/ <- wanna return 404
        application/ <- wanna return 404
        bin/ <- 404
        public/ <- 404
            index.php <- 404
        vendor/ <- 404
        .htaccess  <- 404
        composer.json <- 404
    index.html <- return 200 (OK)

So I write this code to .htaccess
### Define Environment Variables
<IfModule mod_env.c>
    SetEnv CI_ENV development
    SetEnvIf REMOTE_ADDR 192.168.33.1 IsAdmin=1
    #SetEnvIf X-Forwarded-For xx.xx.xx.xx IsAdmin=1
</IfModule>

### Access Restriction By Client IP Address
Order deny,allow
Deny from all
Allow from env=IsAdmin

ErrorDocument 403 /admin/

### Return 404 Error To Denied Clients (To Hide Directory Exists)
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{ENV:IsAdmin} !=1
    RewriteRule .* - [R=404,L]
</IfModule>

But this code affect like this.
document_root/
    admin/ <- 404 (OK)
        application/ <- 403 (NG)
        bin/ <- 403 (NG)
        public/ <- 403 (NG)
            index.php <- 403 (NG)
        vendor/ <- 403 (NG)
        .htaccess  <- 403 (NG)
        composer.json <- 404 (OK)
    index.html <- return 200 (OK)

How can I pretend 403 page to 404 as my desired? Thank you.

A:

I solved this.
### Define Environment Variables
<IfModule mod_env.c>
    SetEnv CI_ENV development
    SetEnvIf REMOTE_ADDR 192.168.33.1 IsAdmin=1
    #SetEnvIf X-Forwarded-For xx.xx.xx.xx IsAdmin=1
</IfModule>

### Access Restriction By Client IP Address
Order deny,allow
Deny from all
Allow from env=IsAdmin

### Replace 403 Page To 404
ErrorDocument 403 /admin/e403.html
ErrorDocument 404 /admin/e404.html

<Files ~ "e40(3|4).html">
    Order allow,deny
    Allow from all
</Files>

### Return 404 Error To Denied Clients (To Hide Directory Exists)
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{ENV:IsAdmin} !=1
    RewriteRule e403.html - [R=404,L]
</IfModule>

Need to write 404 page. (403 page is unnecessary)
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
<p>The requested URL /admin/ was not found on this server.</p>
</body>
</html>

