简体   繁体   中英

Apache Web Server - How to return 404 error instead of 403

I am currently working with an apache .htaccess file. My previous directories were configured to return 403 error. I am now suppose to return 404 error instead of 403(for security purposes). Having no clue of how to do it, I simply replaced all the 403 to 404 in the configuration This is where I arrived to my problem. Out of 50 directories, only a few of them did not change.

For example, These are the few that did not change:

www.example.com/icons/

www.example.com/icons/small/

www.example.com/cgi-bin/

www.example.com/~ftp/

I tried looking up online, did research and try and error for hours. I've tried things like ErrorDocument 404, adding RedirectMatch 404 to the configuration in htaccess and nothing worked for me. Any advice or little form of help? Thank you very much for replying in advance. Any would be appreciated.

You can rewrite your 403 error requests to 404 page using this :

ErrorDocument 403 /404.php

Or redirect to new url 404.php

RedirectMatch 403 ^/404.php

In your htaccess file, add this line

ErrorDocument 403 /yourfolder/404.php

It will still has response 403, so in your 404.php file, add this

<?php http_response_code(404);?>

Your response will be 404

For example, you need to add this lines in your .htaccess

RewriteEngine On
RewriteRule icons/(.*)$ - [R=404,L]
RewriteRule cgi-bin/(.*)$ - [R=404,L]
RewriteRule ~ftp/(.*)$ - [R=404,L]

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