4

I want to prevent directory file listing in all of my folders, so when a user types http://example.com/thisDoesNotExists/, the directory file listing do not show up.

According to a tutorial all I have to do is set IndexIgnore *

I try to set it in the httpd.conf, so I do

<IfModule mod_autoindex>
IndexIgnore *
</IfModule>

at the bottom of the httpd.conf.

It does not work. I get my 404errorPage.html without any styles.

How can I fix this? Thanks.

Disclaimer : I try to set this in httpd.conf and not htaccess because "You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance." According to this.

slevin
  • 4,166
  • 20
  • 69
  • 129
  • So does `http://example.com/thisDoesNotExists/` exist or not? It's unclear exactly what you're trying to do. If you want to `prevent directory file listing in all of my folders` as you say, you should use `Options -Indexes` inside a `` directive. – arco444 Oct 04 '17 at 07:59
  • @arco444 No, `http://example.com/thisDoesNotExists/` does not exist. Here is what I try to do. When you dont set a `IndexIgnore` in Apache and you go to some URL that does not exist, like `example.com/asdrvd` you can see in your browser the dirs and files of the server. By setting `IndexIgnore` the browser does not display any dirs or files, but the page I set in `ErrorDocument 404 "/404errorPage.html"`. But it displays it without styles (no CSS). – slevin Oct 04 '17 at 09:06
  • @arco444 So, either I have to change settings in the `IndexIgnore` to display the `404errorPage.html` with the styles (the CSS) or this cannot be done, so I have to set the `IndexIgnore` to display an unstyled message. – slevin Oct 04 '17 at 09:07
  • 1
    I think you may have some odd configuration somewhere. If you go to a URL that doesn't exist, how can you be returned a list of the files if they don't exist? This is exactly the situation where a 404 error should be returned. Have you checked the linked stylesheet in your 404 page is accessible? Does it use relative paths for example? That sounds more likely to be the problem. The `IndexIgnore` is used to prevent certain files from appearing in the directory listing page, not allowing an error page to display. – arco444 Oct 04 '17 at 09:52

2 Answers2

0

Your <IfModule> argument is wrong so the enclosing directive is never evaluated. The argument either needs to be the modules name (you can see this in the corresponding LoadModule) or the main source filename.

Both "autoindex_module" and "mod_autoindex.c" work.

covener
  • 17,402
  • 2
  • 31
  • 45
  • the `LoadModule` is `LoadModule autoindex_module modules/mod_autoindex.so` and I have uncommented it. I also tried `` and `` and nothing changed. Maybe I did not get what should I do. Can you explain again please? Thanks – slevin Sep 30 '17 at 13:39
0

Here is another way to do it:

You should edit /etc/httpd/conf/httpd.conf, find the code block with

<Directory "/var/www/html">
    Options Index FollowSymLinks
</Directory>

You should remove the Index in there then restart your httpd service by

sudo service httpd restart
user1506104
  • 6,554
  • 4
  • 71
  • 89