hyperlink who's path is only a forward slash (/)
I have been asked to make some changes to a friend's company website. It uses a PHP insert file for the header on each page, which is useful as the开发者_运维技巧 navigation etc is the same on every page.
The following code designates the company logo on every page:
<div id="logo">
<a href="/"></a>
</div>
As you can see, the href
of the a
tag contains only a forward slash /
as it's path.
The link is working fine, and connects to the index.php
page.
I'm wondering how it is doing this? Seeing as the default page for the domain is controlled by the server config file, is this a shortcut to link to whatever the default page is designated as?
I've never seen this done before, and I can't seem to find any documentation concerning it. I appreciate any information you can provide.
That link brings you to the public root, and then the default file kicks in.
It's the relative equivalent of an absolute path, such as http://stackoverflow.com/
In Linux and other Unix-like operating systems, a forward slash is used to represent the root directory, which is the directory that is at the top of the directory hierarchy and that contains all other directories and files on the system. Thus every absolute path, which is the address of a filesystem object (e.g., file or directory) relative to the root directory, begins with a forward slash.
Forward slashes are also used in URLs (universal resource locators) to separate directories and files, because URLs are based on the UNIX directory structure. A major difference from the UNIX usage is that they begin with a scheme (e.g., http or ftp) rather than a root directory represented by a forward slash and that the scheme is followed directly by the sequence of a colon and two consecutive forward slashes to indicate the start of the directories and file portion of the URL.
via: http://www.linfo.org/forward_slash.html
It is a relative URI. Since it consists of just the path part, it maintains the current scheme, host, port etc and so takes you to http://www.example.com/ (assuming you were on http://www.example.com/foo/bar?baz=x#123 )
The browser then requests /
from www.example.com
using http
on the default port (80).
The server then devices what send back. How it does this depends on what the server is and how it is configured.
Since you mention index.php
there will be something that tells the server to use that.
If we use Apache as an example, that will be a combination of the DirectoryIndex directive and something to tell Apache how to handle PHP programmes.
精彩评论