This is not because this website took the time to set up every single directory you would need to make your purchase, but because of a handy module called Mod_Rewrite. Mod_Rewrite allows you to make custom and simplified URLs as needed. In reality, the actual URL may have looked closer to this:

http://www.gizmo.com/gp/itemB004RYVI0Q/ref=as_li_ss_tl?

This tutorial will go over Activating Mod_Rewrite, Creating and Using the required .htaccess page, and setting up the URL rewrites.

The entire URL rewriting operation takes place within the .htaccess file.

Overall, all of the URL rewrite commands follow the same pattern:

RewriteRule Pattern Substitution [OptionalFlags]

Here is a short explanation of each part:

RewriteRule: This is the section in which you can write in the name of the the mod_rewrite directive that you want to use.

Pattern: This section is dedicated to interpreting the requested URL, using regular expressions. This tutorial does not include a discussion of regular expressions, but you can find a useful tutorial on the subject here.

Substitution: This is the actual URL of the page with the information we want to display. It may be hard to remember or confusing because of php paremeters or long strings of numbers. eg. www.cityzoo.com/animals.php?mammals=seals

Optional Flags: A flag is a tag at the end of the Rewrite Rule directive that may change the behavior of of the expression. Some common flags include [F], making the URL forbidden, [NC], forcing the rule to disregard capitalization, [R=301] or [R=302], controlling the redirect code you want to use, [L] indicating that this is the last rule in a series.

Three URL Rewrite Examples:

Example 1: Go to Page A, find page B:

This is the most basic example for a URL rewrite: a visitor to the site types one URL into the browser but is redirected to another.
Here is how to set it up.

Lets go ahead and make two separate pages on for a site—say, one for Apples (apples.html) and one for Oranges (oranges.html):

After that, can make the orange page, substituting all the fruit names to refer to the appropriate one.

Now open up the .htaccess file.

sudo nano /var/www/example.com/.htaccess

Add the following URL rewrite commands to the file:

RewriteEngine on
RewriteRule ^oranges.html$ apples.html

Save and exit.

Once everything is in place, visit the site ending in "/oranges.html"— all of the information displayed will come from the "/apple.html" site.

Now for an explanation:

^oranges.html: this refers to how the page starts. The caret (^) signifies the beginning of a string. In other words-- if the page whose URL we wanted to rewrite began with anything but oranges (eg.navel_oranges.html), it would not be recognized by the rewrite rule, and it would not redirect to apples.html.

$: the dollars sign refers to the URL's end. If there is anything else after the last characters in the string, the web page would be equally unrecognizable by the rewrite rule.

apples.html: this is where the browser is actually directing traffic.

Example 2: The website has a parameter in its URL. How to make it look like a subdirectory.

The first example referred to a site that simply needed to be substituted with another one. The instance below, however, addresses a common scenario that can be seen when there is a parameter in the url.

^products: In order to be caught and rerouted, the URL must start with products (keep in mind that this only refers to the text after the domain name). Should it begin with anything else, the rule will not apply and the URL will stay the same.

([A-Za-z0-9-]+): The content within the parentheses refers to any information that could be typed into the URL. In other words, the URL will be rewritten to reflect whatever a visitor to the site inputs after /products/.

+: The plus sign indicates what is in the brackets can be one or more characters (as opposed to, say, a single character that is either a letter or a number).

/?$: the dollar sign points out the end of the string. The question mark allows the last character in the string to be a forward slash (although it does not require it).

results.php?products=$1: the $1 indicates where the string from the pattern should go. In other words, it will put in the information captured from whatever people wrote in the "([A-Za-z0-9-]+):" part. After the process completes, the browser will display the information from the second URL

[NC]: this is a flag at the end of the phrase, indicating that the rule should ignore the cases of all of the characters in the string.

(meat|produce|dairy): If we want to limit the options that can be typed in, we can specify the only values we will accept: in this case the variety of groceries. If anything besides one of those three 3 keywords is typed in, the URL rewrite will not take place.

The ([^/.]+) indicates that anything can be written between the forward slash besides the characters following the caret, in this case, the forward slash or period.

results.php?products=$1&type=$2&species=$3: Each value in the parentheses will be extracted and then applied to the longer URL in the substitution part of the expression. $1 indicates the first parantheses, $2, the second, $3, the third.