The reason we use index.html
or home.html
or derivitives thereof, is because the webserver software itself actually looks for that and serves it. For example:
This is INVALID: (www-directory)
/var/www/
|_blog.html
|_blog/
|_math.html
|_page2.html
|_page3.html
|_(...)
This will in fact get served as a page listing the folders and files. (Not what you want). You can try this structure, but also make an index.html file next to blog.html. Notice how it will not serve blog.html unless you specify http://www.site.com/blog.html
) This is why http://www.google.com/
shows the page without you having to specify http://www.google.com/index.html
This is VALID:
/var/www/
|_index.html (renamed blog.html to index.html)
|_blog/
|_math.html
|_page2.html
|_page3.html
|_(...)
This will serve your blog.html
file AS THE HOMEPAGE. (Not list all the folders/files in that directory)
The webserver software has (in the config) a specialized list of file names that will be served as the homepage or the main page of a folder. (In my experience, index.html
takes precedence over index.php, so if you have index.html
and index.php
in a folder, the index.html is what the public will see) Of course that can all be changed, and you can even set blog.html
to be recognized as an "index".
Addressing your comment:
"This trick would change the address of my blog from www.xxx.com/blog.html into www.xxx.com/blog/."
This would be done by moving blog.html
entirely into /blog/
and renaming it to index.html.
Your new structure would be:
/var/www/
|_blog/
|_index.html (renamed from blog.html)
|_math.html
|_page2.html
|_page3.html
|_(...)
This should correctly serve http://www.site.com/blog/
to show the contents of your blog.html which we renamed to index.html
so the software could set it as the index of your directory /blog/
You're also free now to put and index.html
file into the root of your site http://www.site.com/(index.html)
to have links to /blog/
and whatever else you wish.
Specifically answering your questions in short statements:
Is it a good practice to have the index.html file in every subfolder or is it intended to be only in the root folder?
Yes, because it prevents people from seeing what files are in your directories. You can prevent this with a
.htaccess
file containingOptions -Indexes
Are there any disadvantages or problems that may occur when using the second, "index in every folder" method?
None that I can think of.
Which one of the two ways of structuring the website described above would you prefer?
I usually have an
index.html
orindex.php
file in the root, subfolders based on category (such asforum
ornews
orlogin
etc.) and then some sort of index inside each of those.