Nginx redirect all 403 to 404

http-status-code-403http-status-code-404nginx

I'm trying to get 403 responses to be exactly identical to 404 ones.

Not sure if there's a proper way to do it, but setting
error_page 403 404
is my current method.

Which works, but it rewrites the url to mysite.com/404 for 403's
while regular 404's leave the url alone.

Oh and I don't have any 4XX custom pages set up and I deleted the default nginx one.

Best Answer

The nginx documentation clearly says that if you want to change the response code, you use =response. For example:

error_page 403 =404 /url;

Note that making this change requires specifying a URL to serve, so you'll have to make something up.

Related Topic