skip to Main Content

As per security reasons, you should throw "404" for hidden directories, but apache is throwing 403 error code. I also checked few answers on stack overflow suggesting showing 404 page on 403 error code, but that is incorrect as we are still seeing 403 error code in Network. I want to show "404 Page Not Found for Hidden Directories". Is there any way to implement my scenario?? I will be ok for redirecting manually all hidden directories, but only with 404 error code.

Can I write Directory Access or anything that can work?

In image, I have tried to explain that I want server to respond with 404 instead of 403 Error codes.

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I have tried enough of things like RewriteCond %{REQUEST_URI} !^/this-path-does-not-exist

    but that didn't work for me... Later, I tried below code and that worked for me.

    Redirect 404 /Directory_Name

    Thanks for the help!!


  2. The best way to accomplish this is by altering the app that generates the 403.

    If you are unable or unwilling to alter the code you can use .htacces to do an internal redirect to a non-existing location. The next line will redirect all requests to the archive directory to a non-existing location.

    RewriteRule  ^archive(/.*)?$ /this-path-does-not-exist [L]
    

    You will also have to add a RewriteCondition for the redirect to your front controller to prevent it from being redirected to your app.

    RewriteCond %{REQUEST_URI} !^/this-path-does-not-exist
    # ... Other rewrite conditions
    # The redirect to your front controller
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search