![]() |
||||||||||||
|
||||||||||||
|
Razer Technology Solutions, Inc.
|
Module mod_rewrite
Tutorial (Part 3): Rewriting URLs In the two preceding
parts of this tutorial we explained the basics of Rules and Conditions. The first example
deals with dynamicall generated pages while the second example will cover
calling Your clients are guided to various detailed product descriptions via a script: http://www.yoursite.com/cgi-bin/shop.cgi?product1 These URLs are included
as links on your site. If you want to submit these dynamic pages to the http://www.yoursite.com/cgi-bin/shop.cgi/product1 Here, the "?"
character has been replaced by "/". Yet
more pleasing to the eye would be a URL of this http://www.yoursite.com/shop/product1 To the search engine,
this appears to be just another acceptable hyperlink, with "shop"
presenting a directory To this effect we will make use of mod_rewrite with the following entries: RewriteEngine on The variables $1 and $2 constitute so-called "backreferences". These are related to text groups. Everything called
in the clicked URL which is located before "shop" plus everything
following "shop/" is RewriteRule ^.htaccess*$ - [F] However, we did not yet achieve a true rewrite in the sense that one URL would be switched to another. For the entry in our current example: RewriteRule ^(.*?)shop/(.*)$ $1/cgi-bin/shop.cgi?$2 this general syntax applies: RewriteRule currentURL rewrittenURL As you can see, this command executes a real rewrite. In addition to installing
the ".htaccess" file, all links in your normal HTML pages which
follow the When a spider visits
a normal HTML page of this kind it will also follow or crawl the product
links because So employing this
method you can convert dynamically generated product descriptions into
seemingly Many webspace providers
running Apache will feature system log files only in common format. What
To effect this, the entries in ".htaccess" should be as follows: RewriteEngine on
"REQUEST_URI" defines the name of the file you expect to be called. In out example this is "robots.txt". The script will now
read the contents of "robots.txt" and will forward them to the
web browser or the search Finally, the visitor
hit is archived in the log file. To this effect, the script will pull
the environmental Here is the source code for the cgi script mentioned above:
To install the script,
upload it to your web site's main or DocumentRoot directory by ftp and
change file A more detailed description
on how to install a script can he found in our online manuals, e.g. here:
RewriteRule ^\robots.txt$ /cgi-bin/text.cgi?%{REQUEST_URI} Note, however, that in this case you will have to modify the paths accordingly in the program script! Finally, here's the solution to our quiz from the previous tutorial: RewriteCond %{REMOTE_ADDR}
^216\.32\.64 Quiz question The regular expression ^216\.32\.64 will apply e.g. to the following strings: 216.32.64 Hence, "4" may be followed by any character string. However, IP addresses
can only have the maximal value 255.255.255.255 - which implies that e.g. Although the two regular
expressions "^216\.32\.64\." and "^216\.32\.64" allow
for different strings, due to
This text may freely be republished or distributed provided the following resource box is included intact either at the beginning or the end of the article and a complimentary copy or notice (link) is sent to the author at the address specified below: Dirk Brockhausen is
the co-founder and principal of fantomaster.com Ltd. (UK) and fantomaster.com
GmbH |
|
|||||
| home · services
· about us · copyright
· the eZine · contact
· customer site Copyright © Razer Technology Company 1999 - 2008. Legal Disclaimer Site Mod:1/2008. |