HTML and CSS Reference
In-Depth Information
the previous code is usually not needed since an unlimited number of subdomains are generally included in the
domain registration price. it is a common practice that domain owners point both the main domain and the www subdo-
main to the same directory of the web server. in other words, is the preferred uri, and users retrieving are redirected to . doing so, users can access the same content with and without www .
Base href
The previous sections discussed absolute URLs. Since many web page components are located in the subdirectories
of the root directory associated with the domain, relative URLs can also be used. They are shorter, however, and not
always convenient. For example, if the hierarchy is too deep and the style sheets are located in a styles directory
three directories above a web page, the path becomes rather long (Listing 4-12).
Listing 4-12. A Long Path in a Complex Web Site
<link rel="stylesheet" type="text/css" href=" ../../../styles/main.css " />
While the parent directory references and the delimiters ( ../../../ ) can be shortened by referring to the root
directory ( / ) instead, this can be omitted by declaring all locations according to the root directory (Listing 4-13). 5
Listing 4-13. Setting a Base Directory for a Web Site
<base href=" " />
The specified URL is used as the base for all relative URLs in the document. By adding the base element to the
document head, the original example can be simplified (Listing 4-14).
Listing 4-14. A Short Path According to the Base Directory
<link rel="stylesheet" type="text/css" href=" styles/main.css " />
Eliminating File Extensions
One of the key techniques for creating permanent URIs is to remove file extensions. On a file-based web server such
as Apache, this can be done by content negotiation [64]. We used content negotiation earlier in the chapter to set the
precedence between MIME types; now we will use it for creating a precedence order for file types. As a result, file
extensions can be kept on the files but can safely be removed from links [65].
Using a type map file, Apache servers can check the directory for all files with the given name and any extension
and select the appropriate one (the one with the highest precedence). A type map file takes precedence over the
extension of the file (even if the special search for implicit file name pattern match, Multiviews , is enabled). The
precedence of a higher-quality image file variant can be set by the qs parameter. In Listing 4-15, the file logo.svg will
be used for all URIs that refer to the file without extension. If there is no SVG version of that file in the directory, the
PNG version will be used.
5 Starting the file path with a / is relative while defining a base directory is absolute referencing.
Search WWH ::

Custom Search