Search and Find

Book Title

Author/Publisher

Table of Contents

Show eBooks for my device only:

 

The Definitive Guide to Apache mod_rewrite

of: Rich Bowen

Apress, 2006

ISBN: 9781430201229 , 160 Pages

Format: PDF

Copy protection: DRM

Windows PC,Mac OSX,Windows PC,Mac OSX geeignet für alle DRM-fähigen eReader Apple iPad, Android Tablet PC's

Price: 53,49 EUR



More of the content

The Definitive Guide to Apache mod_rewrite


 

When Not to Use mod_rewrite (p. 4)

As important as knowing when and how to use mod_rewrite is having a firm grasp on what other tools Apache offers, so that you know when not to use mod_rewrite. All of mod_rewrite’s amazing power comes at the cost of performance. Running regular expressions consumes time and memory, and it’s ideal to avoid it if alternate approaches are available.

However, even when there are one or more alternate approaches, it is seldom the case that one option is clearly the best one to use all the time. There are always a number of factors that you need to consider.

Just as there are several categories in which mod_rewrite use tends to fall, there are also several categories into which common misuse of mod_rewrite falls, as we’ll cover in the following sections.

Simple Redirection
Probably the most common misuse of mod_rewrite is for simple redirection. Redirection is used when a client requests one URL, and we want to give them a different one instead. In many cases, this is a simple one-to-one mapping. That is, it could be a mapping of one URL to another URL, or perhaps one directory to another directory, and sometimes even a mapping of one virtual host to another one, or perhaps to another server entirely.

In each of these cases, the Redirect directive is sufficient. The syntax of the Redirect directive is as follows:

Redirect [Original] [Target]

where [Original] is the URL that was originally requested, and [Target] is the fully qualified URL to which you wish to redirect it. When the user requests the original URL, Apache will send a redirection message back to the browser, which will then request the new URL.

The address appearing in the address bar of the user’s browser will change to the new URL. This approach requires a second round-trip to the web server in order to retrieve the content. The advantage of this approach, in addition to simplicity, is that the new corrected URL is announced to the user (who may or may not notice), but also that an automated process such as a search engine indexer will update its records to reflect the new URL and stop requesting the old one.

Several examples of the Redirect directive follow:

Redirect /index.cfm http://www.example.com/index.php

In this example, only one possible URL is redirected. That is, if someone requests

http://www.example.com/index.cfm, they will be sent instead to

http://www.example.com/

index.php, but no other URLs will be affected.

In this next example, we’ve renamed our /pics/ directory to /images/ instead, and we want all requests for things in /pics/ to go to /images/ instead:

Redirect /pics/ http://www.example.com/images/