Why do people name their files index.html? - html

I have seen a lot of people been using that file name for their HTML files. I wonder why? I'm kind of new to HTML, I haven't learned much, but when I name my HTML files, I name them whatever I want. When I have been searching up examples of HTML, I have found they name it index.html. Why?

I have seen a lot of people been using that file name for their HTML files
You would typically use that name for one of your page, and it would usually be the home page.
When you arrive a website, for example www.website.com, you're not pointing to a file (like you would be if you typed www.website.com/about.html), you're pointing to a directory listing of all the files.
The webserver will try to serve a file, typically called index.html or index.php by default, but it could be something different, and it's configurable by editing your webserver's config files.
If the server doesn't find any file to serve (because you didn't include an index.html file or because you renamed it without editing the server's config) you will see a listing of the files, which is rarely the desired behavior, especially at the root of a website.

Generally the contents of index.html will be returned when just the directory is requested.
e.g. http://example.com/index.html is returned for a request for http://example.com
This is merely convention and is usually configurable.

Here is my take: It was likely named 'index' in the original internet because it is the 'indexing page' that directs to the sub pages, and you would go back to the index page to go to another page. This was before images and search engines. Later it got more advanced with a menu on all pages. This is how I remember it, but it's a long time ago.
https://twitter.com/PresidentUSW1/status/1442236777293496325?s=20

The default landing page of many Web servers defaults to index.html or default.htm and either way it's simply a start page. It's not necessary at all.

Related

Have Domain Open HTML File?

I am currently making a website, and have a folder containing CSS3 and HTML5 code in it. When I click on the index.html file, it opens up a local file and I can see my design and text in it. However, I am not sure how to have my website "point" to the index.html file, so it shows the content that is in the file. (I bought the domain with GoDaddy).
Thanks for the help!
Make Sure the directory does not have any other default files like default.php,default,html,etc and also there should be only one index file. if there is any index.php it will overtake index.html. Please make your question more clear and tell use which hosting are you using.....
Check documentation of the company that provides you hosting - the server has a list of files it looks for on disk in a given order. Only thing you need to do is to rename you file to match server's "lookup table".
Relevant part of configuration of the most popular web servers:
apache: https://httpd.apache.org/docs/current/mod/mod_dir.html
nginx: http://nginx.org/en/docs/http/ngx_http_index_module.html

Link not going back to home page

I have researched this to death including on this page. My index page is outside my html folder and when I hit the nav link it will not take me back home(index page). I have seen a few post on here regarding this situation, see below:
There are also two special directory names: . and ..:
. means "current directory"
.. means "parent directory"
but I have tried several see below for examples that I have tried. The index page is on/in the root directory (folder), all the other nav links work as they are in the html folder and they are up one level.
I have tried:
Index
Index
Index
Index
Out of desperation I have tried several things I knew would not work, I would really appreciate your assistance in this matter.
littleone
In my opinion the safest way is using
index
This will move the user to the root directory no matter in which directory the user currently is.
It's quite short which can be helpful too. In most cases you can omit index.html because the server uses this file automatically if you visit a directory.
I'm no web server specialist, but I'm sure you're saving your index.html in the incorrect location.
Your /html folder is your ROOT folder, anything outside of it isn't accessible via a URL. I'm sure there are ways to override that, but I have never seen anyone do this even in the most complex projects I've worked in.
For example, your site www.yoursite.com is located in the /html of your server. So if you have your index.html file outside of that folder, that file can't be accessed or served at all.
The common sense solution is to move your index.html file to the /html folder. When you do this you can then use a slash in your href, like so:
Index

Do I need to specify a webpage's url?

I've uploaded several files to my server and it's really quite baffling. The home page is saved as index.html, and when I type in the URL of said page it miraculously, and quite successfully shows the right page. What about my other pages? I have linked to them from the home page with the following code:
About Us
How does my html file, presumably called about.html, supposed to know that its URL is "http://www.example.com/about/"? I am dubbing this "The Unanswered Question" because I have looked at numerous examples of metadata and there is nothing about specifying the URL of a page.
It depends on what type of server you are running.
Static web servers
If it is the simplest kind of static file server with no URL aliasing or rewriting then URLs will map directly to files:
If your "web root" was /home/youruser/www/, then that means:
http://www.example.com -> /home/youruser/www/
And any paths (everything after the domain name) translate directly to paths under that web root:
http://www.example.com/about.html -> /home/youruser/www/about.html
Usually web servers will look automatically for an "index.html" file if no file is specified (i.e. the URL ends in a /):
http://www.example.com/ -> /home/youruser/www/index.html
http://www.example.com/about/ -> /home/youruser/www/about/index.html
In Apache, the filename searched for is configurable with the DirectoryIndex directive:
DirectoryIndex index.html index.txt /cgi-bin/index.pl
That means that every request to a path that ends in a / (and to add yet another rule, under some common settings it will automatically append a / if the path is the name of a directory, for example 'about'):
http://www.example.com/ -> /home/youruser/www/index.html
-> or /home/youruser/www/index.txt
-> or /home/youruser/www/cgi-bin/index.pl
Web servers with path interpretation
There are too many different types of servers which perform this functionality to list them all, but the basic idea is that a request to the server is captured by a program and then the program decides what to output based on the path.
For example, a program might perform different routes for basic matching rules:
*.(gif|jpg|css|js) -> look for and return the file from /home/user/static
blog/* -> send to a "blog" program to generate the resulting page
using a combination of templates and database resources
Examples include:
Python
Java Servlets
Apache mod_rewrites (used by Wordpress, etc.)
Links in HTML pages
Finally, the links in the HTML pages just change the URL of the location bar. The behavior of an HTML link is the same regardless of what exists on the server. And the server, in turn, only responds to HTTP requests and only produces resources (HTML, images, CSS, JavaScript, etc.), which your browser consumes. The server only serves those resources and does not have any special behavioral link with them.
Absolute URLs are those that start with a scheme (such as http: as you have done). The whole content of the location bar will be replaced with this when the user clicks the link.
Domain relative URLs are those that start with a forward slash (/). Everything after the domain name will be replaced with the contents of this link.
Relative URLs are everything else. Everything after the last directory (/) in the URL will be replaced with the contents of this link.
Examples:
My page on "mydomain.com" can link to your site using the Example.com about just as you have done.
If I change my links to about then it will link to mydomain.com instead.
An answer your question
How does my html file, presumably called about.html, supposed to know that its URL is "http://www.example.com/about/"?
First, the file itself has no idea what its URL is. Unless:
the HTML was dynamically generated using a program. Most server-side languages provide a way to get this.
after the page is served, client-side scripts can also detect the current URL
Second, if the URL is /about and the file is actually about.html then you probably have some kind of rewriting going on. Remember that paths, in their simplest, are literal translations and /about is not the same as about.html.
Just use /about.html to link to the page
Theoretically, it's better for URLs in your documents to be relative, so that you don't have to change them in the event you change the domain or the files location.
For example, if you move it from localhost to your hosted server.
In your example, instead of www.example.com/about.html use /about.html.
Given the link above you would need a about page named index.html located in a directory named about for your example to work. That is however not common practice.
I'm a bit confused, but here is some information. Any file named "index" is the default display page for any directory(folder) when trying to view that directory.
All files in a folder are always relative to that directory. So if your link is in a file, within a different directory, then you must type in that directory along with the file. If it is the same directory, then there is no need to type in that directory, just the file name.
about.html doesn't know what it's URL is, its the index.html file that calls your about.html file.
When you're in any given directory, linking to other pages within that directory is done via a simple relative link:
About Us
Moving up a directory, assuming you're in a sub folder (users) perhaps you can use the .. operator to navigate up one directory:
About Us
In your case your about page is in the same directory as the page you're linking from so it just goes to the right page.
Additionally (and I think this may be what you're asking) if you have:
about.html
about.php
about.phtml
about.jpg
for example, and you visit http://www.yoursite.com/about it will automatically bring up the html page and the other pages should be referenced explicitly somewhere if you want them to be used.

Opening directories in HTML

In some websites, I see links that look like this:
Link
The link doesn't go to an html file, but a folder (I believe). I was wondering if this has any purpose, and how to do this. Is there a default file to open when opening a directory? Because when I try something like this, I click the link, then I see a list of files in that folder, and I have to click on the proper link.
Everywhere I look, it says you should do links like this:
Link
Should I just let it go? I'm awfully curious.
This is something that is controlled by the web server. Some will look for a file called default.htm, others will look for index.html. It's usually configurable, and sometimes the server may look for any of a number of variations of index or default.
If such a file is not found, the server will often display a directory listing of all the files found in that folder, but usually that's not a good idea for security reasons. Again, this is something that can be controlled in the settings for the server.
Allowing directory listing is VERY dangerous and ill-advised practice. You should hide real directory structure of your site by all means.
PHPDL is a Php script that lists all the files in a directory (except itself of course). What sets PHPDL apart is that everything the script needs is in one file, including the file-type icons it uses.
Note: You can rename the script to anything you want. It will not list itself as a file to download.
This script safe and usefull, see demos:
http://greg-j.com/projects/phpdl/PHPDL-v2.php
http://greg-j.com/projects/phpdl/PHPDL-lite.php

web-development: how do you usually handle the "under costruction" page"?

I was wondering what's the best way to switch a website to a temporary "under costruction" page and switch it back to the new version.
For example, in a website, my customer decided to switch from Joomla to Drupal and I had to create a subfolder for the new CMS, and then move all the content to the root folder.
1) Moving all the content back to the root folder always create some problems with file permissions, links, etc...
2) Creating a rewrite rule in .htaccess or forward with php is not a solution because another url is shown including the top folder.
3) Many host services do not allow to change the root directory, so this is not an option since I don't have access to apache config file.
Thanks
Update: I can maybe forward only the domain (i.e. www.example.com) and leave the ip on the root folder (i.e. 123.24.214.22), so the access is finally different for me and other people? Can I do this in .htaccess file ?
One thing to consider is you don't want search engines to cache your under construction page - and you also don't want them to drop your homepage from the search index either (Hence just adding a "noindex" meta tag isn't the perfect solution).
A good way to deal with this is do a 302 redirect (temporarily moved) from your homepage to your under construction page - that way the search engine does not cache your homepage as an under construction page, does not index your under construction page (assuming it has a NOINDEX meta tag), and does not drop your homepage from the search index either.
One way would be the use of an include on your template page.
When you want the construction page to show, you set a redirect in the include to take all traffic to the construction page.
When you are done your remove the redirect.
What about hijacking your index.php file?
Something simple, along the lines of
<?php
if (SITE_OFFLINE)
include 'under_construction.html';
else
//normal content of your index page
?>
where you would naturally define SITE_OFFLINE in an appropriate place for your needs.
What I did when I used PHP for websites was to configure Apache to direct all requests to a front controller. You then would have full access to all requests no matter where they are pointing to. Then in your front controller (PHP file, static html file, etc.), you would do whatever you need to do there.
I believe you need to configure pathinfo in Apache and some other settings, it has been about 3 years since I have used that approach. But, this approach is also good for developing your own CMS or application so that you have full control over security.
You have to do something similar to this:
http://www.phpwact.org/pattern/front_controller
I am looking for more details, I know my configuration had more to it than that.
This is part of what I'm looking for too:
http://httpd.apache.org/docs/2.0/mod/core.html
Enabling path_info passes path information to the script, so all requests now go through a single point of entry. Let me find my configuration, I know vaguely how this works, but I'm sure it looks like a lot of hand waving.
Also, keep in mind that because all requests are going through this single PHP file, you are responsible for serving images, JavaScript, CSS, etc. So, if a requests is coming in for /css/default.css, that will go through your php script (index.php, most likely), then you'll need to determine how to handle the request. Serving static files is trivial, but it is a little more work.
If you don't want to go that route, you could possibly do something with mod_rewrite so that it only looks for .html, .htm pages or however you have your site configured. For me, I don't do extensions, so that made my regex a little more difficult. I also wanted to secure access to all files. The path_info was the solution for me, but if you don't need that granularity, then writing a front controller might be a bit too much work.
Walter