mipadi
mipadi

Reputation: 410762

Is there a way to return 404 Not Found for prohibited directory listings in Apache?

My web server is Apache. I have disabled directory listings via an Options -Indexes directive in a .htaccess file, so if a user navigates to a directory without an index.html file, he'll get a 403 Forbidden error. However, I'd like to return 404 Not Found in such instances instead. Is that possible?

Upvotes: 1

Views: 944

Answers (3)

Jekis
Jekis

Reputation: 4685

RedirectMatch 404 ^/prohibited/directory/$

Upvotes: 2

Ofri Raviv
Ofri Raviv

Reputation: 24823

You can use

ErrorDocument 403 /path/to/your/error/file/or/script

to override 403 with your own script, and make it return 404. for example, in PHP:

<?php
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
?>

Upvotes: -1

Sam Dark
Sam Dark

Reputation: 5291

You can try using mod_rewrite for it:

RewriteEngine On  RewriteRule
my_hidden_dir.* not_found.php

Upvotes: 0

Related Questions