如何在apache 2.4上假装403页面到404?
这是我的目录结构,我使用codeigniter 3。
document_root/
admin/ <- codeigniter project
application/
bin/
public/
index.php
vendor/
.htaccess <- access restriction write to here.
composer.json
index.html <- front page
我想拒绝来自未经认证的IP地址的访问权限。返回响应代码404,Not 403.(Cuz想隐藏目录存在)
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)
所以我将此代码写入.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>
但是这段代码会像这样影响。
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)
如何按照我的要求假装403页到404?谢谢。
我解决了这个问题
### 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>
需要写404页面。 (不需要403页)
<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>