 |
|
|
| Apache Mod Rewrite |
| Mod
Rewrite is a module that can be used with the Apache web server.
This module is designed so that a URL can be rewritten, in other
words, when you request a web page in a web browser the address
in your browser typically maps directly to a file on the web server.
But this doesn't have to be the case, with mod rewrite you can change
things round a little bit. Take a simple example:
(1)
http://www.lgr-uk.co.uk/products/search.php?fruit=apple&type=granny-smith
(2) http://www.lgr-uk.co.uk/products/fruit/apple/type/granny-smith |
In example (1) you can see which file on the server we are requesting
(search.php). The characters following the ? are what we call a
query string, all this means is that we are passing this information
to the script on the server and we will then process it - in this
example that would probably mean getting the price of a granny smith
apple. If you look at the second example the URL looks much cleaner
but it is not as obvious what is going on any more. Using mod rewrite,
example (2) above can be rewritten so that is has exactly the same
functionality as example (1), in fact it could even use the same
script on the server to do the work (search.php).
There any many powerful ways in which Mod Rewrite can be used,
perhaps the most common is when a particular page on your website
is moved, perhaps following a bit of a "spring clean"
of your website. As a result of moving this web page any links to
the old location will now be broken. However, with mod rewrite you
can simply forward anyone attempting to view the old page to the
new one. A second very common usage of mod rewrite is to enable
websites with dynamic content to get their content listed in search
engines - historically search engines have struggled to index content
on dynamic pages which look like example (1) above, rewriting the
URL as example (2) overcomes this problem and can help websites
benefit from greater traffic from search engines.
|
|
|
| |
|
|