我有一个网站 example.com
我还有以下目录下的子目录:
example.com/dir1/
example.com/dir2/
example.com/dir3/
现在,如果他们试图访问,我希望将访问者重定向到404:
example.com/dir1 /
但不是以后,当他们尝试访问时:
example.com/dir1/example.php
以下是我的.htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]
Options -Indexes
上面的htaccess当我尝试访问任何子目录时,我得到一个默认错误:
Access forbidden!
You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.
If you think this is a server error, please contact the webmaster.
Error 403
localhost
Apache/2.4.16 (Win32) OpenSSL/1.0.1p PHP/5.6.12
答案 0 :(得分:1)
尝试在.htaccess文件中使用它!
ErrorDocument 404 /filenotfound.html
IndexIgnore *
答案 1 :(得分:0)
尝试:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L,R=404]
答案 2 :(得分:0)