.html filenames

aka Rohan's picture

He has: 200 posts

Joined: Feb 2006

Ok this probably has a really obvious answer but i'm a bit of a simpleton when it comes to html. Shocked

Should all pages in a website be called index.html e.g.

yourdomain.com/index.html
yourdomain.com/subfolder/index.html
e.t.c.

Or is it acceptable to name them anything you want e.g.

yourdomain.com/subfolder/newpage.html? Smiling

mik-crap's picture

He has: 30 posts

Joined: Jan 2007

Not all webpages should be called index.html, just the first page you want people to see when they view each directory of your site.

You can use .htaccess or a server-side scripting language to automatically redirect the user to your true homepage.

RewriteCondition %{HTTP_HOST} ^(domain.com/|domain.com/index.html)$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/truehome.html$ [R=301,L]
'
The above would appear in the .htaccess file of your root. Change domain.com, and truehome to the values you want. This script would automatically redirect people from http://www.domain.com/ or http://www.domain.com/index.html to http://www.domain.com/truehome.html

Alternatively, a much nicer way would be:

<?php
header
('Location: truehome.php');
?>

But that is based on the assumption your server supports php.

You could also edit (if you own the server or have access to) the httpd.conf to use whatever.html as your index.

mik-crap's picture

He has: 30 posts

Joined: Jan 2007

conrad;213363 wrote: ...if your using a microsoft server you can change the starting pages in the IIS server and add the file type. Also, without going too far into it, you can also define your own extensions and say how to handle them. For example I could say that all files with the extension .csh are processed with html. But thats a big world all on it's own Smiling

You can do this in Apache as well. Simply edit the httpd.conf or .htaccess file with the filename and extension. It is strongly recommended that you never use .htaccess as it increases page generation times and server stress.

To add a file extension in the .htaccess use
AddType text/html .ext'

To add a file extension in the httpd.conf use

<Directory /www/htdocs/>
AddType text/html .ext
</Directory>
'

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

Well, technicalities aside (mod-rewrite and such) using index.html it does make things a little easier.

So instead of having: [incode]jsworld.co.uk/funtybunt/apagenameandthat.html[/incode] you could have: [incode]jsworld.co.uk/funtybunt/[/incode] and the server will know that it should get [incode]jsworld.co.uk/funtybunt/index.html[/incode]

Using index.html makes URL's look nicer and involves less typing. There's also the consideration that if you have: [incode]jsworld.co.uk/funtybunt/apagenameandthat.html[/incode] a person may be able to type in: [incode]jsworld.co.uk/funtybunt/[/incode] and get a listing of all the files and directories in the funtybunt directory. That does depend on how your server is setup though, and most of the time it makes no difference if people can see that stuff.

a Padded Cell our articles site!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.