A free and open-source book on Zend Framework for beginners


5.1. URL Structure

To better understand routing, we first need to look at the URL structure. A typical URL from an HTTP request consists of several parts. There are scheme, host name, path, fragment and query parts.

For example, let's look at the URL "http://site1.yourserver.com/path/to/page?a=1&b=2#section" (figure 5.1).

Figure 5.1. Typical URL structure Figure 5.1. Typical URL structure

This URL begins with the scheme (the scheme typically looks like http or https). Then, the host name follows which is the domain name of your web server (like site1.yourserver.com). Optional path segments (separated by '/' character) follow the host name. So if you have the path part "/path/to/page" then "path", "to", and "page" would each be a path segment. Next, after the question mark, the optional query part follows. It consists of one or several "name=value" parameters separated from each other by an ampersand character ('&'). Finally, after the hash ('#'), we have the fragment name.

Each part in a URL uses special character encoding, which is named the URL encoding. This encoding ensures that the URL contains only "safe" characters from the ASCII 3 table. If a URL contains unsafe characters, they are replaced with a percentage character ('%') followed by two hexadecimal digits (for example, the space character will be replaced by '%20').

3) ASCII (American Standard Code for Information Interchange) is a character set which can be used to encode characters from the English alphabet. It encodes 128 characters: digits, letters, punctuation marks and several control codes inherited from Teletype machines.


Top