Reputation: 13
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:
<a href="http://www.example.com/about/">About Us</a>
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.
Upvotes: 1
Views: 872
Reputation: 33197
It depends on what type of server you are running.
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
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:
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.
http:
as you have done). The whole content of the location bar will be replaced with this when the user clicks the link./
). Everything after the domain name will be replaced with the contents of this link./
) in the URL will be replaced with the contents of this link.Examples:
<a href="http://www.example.com/about/">Example.com about</a>
just as you have done.<a href="/about">about</a>
then it will link to mydomain.com
instead.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:
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
.
Upvotes: 3
Reputation: 3283
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:
<a href="/about.html">About Us</a>
Moving up a directory, assuming you're in a sub folder (users) perhaps you can use the ..
operator to navigate up one directory:
<a href="../about.html">About Us</a>
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.
Upvotes: 0
Reputation: 2011
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.
Upvotes: 0
Reputation: 12341
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
.
Upvotes: 1
Reputation: 294
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.
Upvotes: 0