0

In my /subwebpage/ folder I do contain an index.html file.

When im visiting my website like this: www.website.com/subwebpage the index.html file is loading automatically. Even the URL don't display www.website.com/subwebpage/index.html

I would like to prevent the auto loading of the index.html file. This means, the index.html should only load, if the client is the URL: www.website.com/subwebpage/index.html

What do I have put into my .htaccess to do this?

I tried with:

# Deny access to everything by default
Order Deny,Allow
deny from all

But it didn't help.

Baku Bakar
  • 442
  • 2
  • 8
  • 20
  • in this post are a possible solution: [https://stackoverflow.com/questions/19322345/how-do-i-change-the-default-index-page-in-apache](https://stackoverflow.com/questions/19322345/how-do-i-change-the-default-index-page-in-apache) – Alejandro Granados Feb 19 '19 at 21:14
  • @AlejandroGranados this link does not really answer my quesiton. – Baku Bakar Feb 19 '19 at 21:51
  • @EmbaBakar That SO question though should be your solution. If you change your default page to something else, like loadme.html, it won't load index.html unless you put it in the URL. – CodeLikeBeaker Feb 19 '19 at 22:17
  • Possible duplicate of [How do I change the default index page in Apache?](https://stackoverflow.com/questions/19322345/how-do-i-change-the-default-index-page-in-apache) – CodeLikeBeaker Feb 19 '19 at 22:18

1 Answers1

1

You need to change the DirectoryIndex property in the .htaccess

This property tells the server which filename.filetype combination serves as the default file to be shown when none is provided. It can also accept multiple values separated by whitespace for fallback purporses i.e. if the first one is not found, check the second one etc.

The default property is:

DirectoryIndex index.html

To prevent your server from showing index.html by default, just change the index.html value of the DirectoryIndex property to something that does not exist, for example:

DirectoryIndex filethatdoesnotexist.html



For reference of what I mentioned, this this property can have multiple values separated by whitespace like this:

DirectoryIndex index.html default.html first.html

This means that if the server doesn't find the index.html it looks for default.html and if it doesn't find it either it looks for first.html etc.

Ivica Pesovski
  • 827
  • 7
  • 29
  • Thank you for the reply. But actually the .htaccess is in the folder `public_html/secure`. And the folder that I want to prevent to load `index.html` is on `public_html/secure/app`. In that case, where do I have to add this `DirectoryIndex`? One more quesiton: Does it have to be between `` and `` – Baku Bakar Feb 19 '19 at 22:18
  • Just create another .htaccess file inside /public_html/secure/app – Ivica Pesovski Feb 19 '19 at 22:29
  • You can have as many .htaccess files as you want, every one that is in a nested folder will have priority before the one inherited from the parent folder(s). – Ivica Pesovski Feb 19 '19 at 22:30
  • And you do not need to put it inside , it can be just a one-line .htaccess file with the rule from above. – Ivica Pesovski Feb 19 '19 at 22:31
  • 1
    Thank you for the information. It works great, thank you a lot Ivica Pesovski! – Baku Bakar Feb 19 '19 at 22:31