简单地说,我想让它,如果用户去一个文件夹,它会给一个404 Error
。问题是,它似乎不起作用!
这是我的文件设置:
- postin
- mail
- yourmail.php
- profiles
- viewprofile.php
- .htaccess
- error.php
然后我简单地把它添加到我的。htaccess:
RewriteRule ^mail/ - [L,R=404]
ErrorDocument 404 error.php
我认为通过添加这段代码,如果用户输入URL .../postin/mail/
,它将把用户带到404 error.php页面。这似乎不是这样的情况下,虽然,它只会带来目录页的.../postin/mail/
。所以我的问题是,当用户进入文件夹(目录)时,我如何引发404错误?
如果你想要我完整的。htaccess,它在这里:
Options +FollowSymLinks
RewriteEngine on
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule search/(.+)/?$ search.php?query=$1 [NC,L]
RewriteRule search/?$ search.php [NC,L]
RewriteRule register/?$ registerpage.php [NC,L]
RewriteRule login/?$ loginpage.php [NC,L]
RewriteRule home/?$ home.php [NC,L]
RewriteRule users/?$ users.php [NC,L]
RewriteRule error/?$ error.php [NC,L]
RewriteRule ^mail/ - [L,R=404]
ErrorDocument 400 http://localhost/postin/error
ErrorDocument 401 http://localhost/postin/error
ErrorDocument 403 http://localhost/postin/error
ErrorDocument 404 http://localhost/postin/error
ErrorDocument 500 http://localhost/postin/error
ErrorDocument 502 http://localhost/postin/error
ErrorDocument 504 http://localhost/postin/error
<Files .htaccess>
order allow,deny
deny from all
</Files>
您可以使用:
DirectoryIndex /errorpage.php
这应该是你的htaccess的第一行