简体   繁体   中英

.htaccess rewrite rule redirect to 404 page

I have a few folders such as php_includes templates and a few others and I am adding a .htaccess file for them all. So far what I have works if the user trys to directly access the file in the address bar, but I'd rather it send it to a 404 page.

IndexIgnore *
# no one gets in here!
deny from all
#error 404
ErrorDocument 404 /error/404.html

Is there something wrong with my .htaccess All I feel like is happening is the deny from all is taking over so the 404 won't work directly. Though I've tried this with a different .htaccess file for the main site, and the 404 isn't working in there either.

Same ErrorDocument as the others but here is how my directory is set up

  -.htaccess
 --public_html
   --error
     --404.html
 --admin

So maybe I am either getting the ErrorDocument incorrect for my .htaccess that or I have the path directory incorrect. Can someone please explain what the issue here is?

note I am using 000webhost if that matters sometimes I see them doing some silly stuff, and this is just a testing server.

Since you are using deny directive it sends error code 403 .

Declare your custom handler for 403 :

ErrorDocument 403 /error/404.html

The deny from all directive will generate a 403 error. So just do this

ErrorDocument 403 /error/404.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM