Why? 403 (forbidden) HTTP status code gives a clue about a correct path, and you don’t have permission to access it. This confirms file/folder exists and it’s restricted. Thus, 403 allows the hacker to know more about your file system structure and room for security vulnerabilities. It’s a good idea to redirect 403 return code to 404 (not found), so there is no room for a guess. This is often asked to implement in the payment industry or transactional application production system. There are multiple ways to get this done and following I’ve explained doing in Apache HTTP, Nginx. Note: take a backup of the necessary configuration file before modifying. And if possible, test in non-production first.

Apache HTTP

We will use ErrorDocument directive to achieve this

Create a file at DocumentRoot level which will be served at 404 Let’s name the file 404 Add the following in httpd.conf file

Above, I am instructing Apache to serve /404 file whenever 403 occurred

Save the configuration file and restart Apache to test it

Nginx

Let’s use error_page directive to get this done

Create a file name called 404.html Add the following in server section under Nginx configuration file

Above, in the first line, Nginx will serve /404.html whenever file not found and the second line, /404.html will be served whenever requested resources return 403.

WordPress

You can use the Custom Error Pages plugin which allows you to setup a custom page for 401 and 403 status code. I hope this helps you. If you are interested in learning Web Security then I would suggest checking out this course.

Redirecting to 404 from 403 - 15Redirecting to 404 from 403 - 57Redirecting to 404 from 403 - 12Redirecting to 404 from 403 - 6Redirecting to 404 from 403 - 4Redirecting to 404 from 403 - 47Redirecting to 404 from 403 - 25Redirecting to 404 from 403 - 39Redirecting to 404 from 403 - 32Redirecting to 404 from 403 - 58Redirecting to 404 from 403 - 59Redirecting to 404 from 403 - 25Redirecting to 404 from 403 - 23Redirecting to 404 from 403 - 64Redirecting to 404 from 403 - 15Redirecting to 404 from 403 - 39Redirecting to 404 from 403 - 58Redirecting to 404 from 403 - 52Redirecting to 404 from 403 - 95Redirecting to 404 from 403 - 69Redirecting to 404 from 403 - 48Redirecting to 404 from 403 - 4Redirecting to 404 from 403 - 1