Stephen Walsh
Stephen Walsh

Reputation: 835

Have index.html file but still getting a directory listing

I have an index.html file in my Apache DocumentRoot directory but when I go to my URL, I am still getting a directory listing of my DocumentRoot directory instead of the index.html file being displayed. The apache access_log shows 200's when I reload the page. Any suggestions?

Upvotes: 0

Views: 3769

Answers (2)

S0AndS0
S0AndS0

Reputation: 920

Not saying this will fix it for you, but for me when first getting started with Apache2 it was file permissions that would get forgotten when moving or writing new file under the web root directory

ls -hal /var/www/host_one/index.html

If above doesn't have read (r) permissions for the same user:group or if the ownership doesn't include the user/group of the web server, then try the following for allowing group reads

# Modify ownership, change 'www_host' to Apache2 group
chown ${USER}:www_host /var/www/host_one/index.html
# give read+write (6) to user and read (4) to group owners
chmod 640 /var/www/host_one/index.html

Try refreshing the website and see if permissions where the issue. Note most web documents only require read permissions and ownership to be correct for browsers to be allowed to pick them up for rendering, on rare occasions you may need executable (1 or x) permissions for server scripts (be cautious of ownership in such cases) and last write permissions (2 or w) should likely never be seen without good reasons on files within your web root.

Second thing to try, use the index.html within your browsers URL bar

# by IP
http://192.168.0.100/index.html
# by domain
http://site-name.local/index.html

If the above loaded your document then, like @Pekka 웃 stated already, you've likely got a server option that's missing or enabling directory listings instead of looking for a index page within that directory. If this is the problem then there's two ways of fixing it that I've tried in the past. One, htaccess configuration to disable directory listing within that sub-directory, two, server vhost configuration to prevent whole site from directory listings. Personally I prefer to use option two and then on directories that should be allowed to be listed place an htaccess config for permissions instead of denials.

Upvotes: 0

Pablo Recalde
Pablo Recalde

Reputation: 3571

Use

DirectoryIndex index.html

It tells apache what document to show for a directory request.

update

You should specify just the filename that apache will look for in the folder requested.

Upvotes: 5

Related Questions