Tuesday, February 24, 2009

Basic Of HTML & XHTML Lesson 9

Parts of URLs

Whenever you venture out to the Web, it's inevitable that you'll encounter URLs. They are the street addresses of the Internet.

After completing this lesson, you should be able to:

Dissect a basic URL into three main sections
Create URLs that employ special characters





Most Uniform Resource Locators (URLs) contain three parts: the protocol, the hostname, and the directory and filename. The protocol is the way in which the page is accessed; that is, the means of communication your browser uses to get the file. If the browser uses HTTP to get to the file, the protocol part is http.

If the browser uses FTP, the protocol is ftp. The protocol matches an information server that must be installed on the system for it to work. You can't use an FTP URL on a machine that does not have an FTP server installed, for example.




The hostname is the Internet system on which the information is stored. You can have the same hostname but have different URLs with different protocols, such as http://mysystem.com or ftp://mysystem.com.




Finally, the directory is the location of the file or other form of information on the host. The directory can be an actual directory and filename, or it can be another indicator that the protocol uses to refer to the location of that information. Gopher directories, for example, aren't explicit directories.




Special Characters in URLs

A special character in a URL is anything that is not an upper- or lowercase letter, a number (0–9), or one of the following symbols: dollar sign ($), dash (-), underscore (_), period (.), or plus sign (+). You might need to specify any other characters by using special URL escape codes to keep them from being interpreted as parts of the URL itself.

URL escape codes are indicated by a percent sign (%) and a two-character hexadecimal symbol from the ISO-Latin-1 character set (a superset of standard ASCII). For example, %20 is a space, %3f is a question mark, and %2f is a slash.





Suppose that you have a directory named All My Files. The first URL you write to link to this directory is:

Because the spaces are considered special characters to the URL some browsers might have problems with them and not recognize the pathname correctly.





For full compatibility with all browsers, use %20 to replace spaces in file names.

Most of the time, if you make sure that your file and directory names are short and use only alphanumeric characters, you won't need to include special characters in URLs. Keep this point in mind as you write your own pages.

No comments:

Post a Comment