If you want to submit these dynamic pages to the search engines, you are confronted with the problem that most of them will not accept URLs containing the "?" character.
However, it would be perfectly possible to submit an URL of the following format:
To the search engine, this appears to be just another acceptable hyperlink, with "shop" presenting a directory containing files "product1", "product2", etc.
If a visitor clicks this link on a search engine's results page, this URL must be reconverted to make sure that "shop.cgi?product1" will actually be called.
To this effect we will make use of mod_rewrite with the following entries:
RewriteEngine on Options +FollowSymlinks RewriteBase / RewriteRule ^(.*)shop/(.*)$ $1cgi-bin/shop.cgi?$2
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 defined by and stored in the two variables $1 and $2
Up to this point our given examples made use of rules such as this one:
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/(.*)$ $1cgi-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 format "cgi-bin/shop.cgi?product" must be changed to: "shop/product" (without the quotes).
When a spider visits a normal HTML page of this kind it will also follow or crawl the product links because there is no question mark contained in the link anymore to prevent it from doing so.
So employing this method you can convert dynamically generated product descriptions into seemingly static web pages and feed them to the search engines.
---------
In our second example we will discuss how to redirect calls for ".txt" files to a program script.
Many webspace providers running Apache will feature system log files only in common format. What this means is that these logs will not store visitor Referrers and UserAgents.
However, in relation to "robots.txt" calls it is preferable to have access to this information in order to learn more about visiting spiders than merely their IPa.
To effect this, the entries in ".htaccess" should be as follows:
RewriteEngine on Options +FollowSymlinks RewriteBase / RewriteRule ^\robots.txt$ /text.cgi?%{REQUEST_URI}
Now, when "robots.txt" is called, the applied Rule will redirect your visitor to the program script "text.cgi".
Furthermore, a variable is conveyed to the script which will be processed by the program.
"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 engine spider.
Finally, the visitor hit is archived in the log file. To this effect, the script will pull the environmental variables "$ENV{'HTTP_USER_AGENT'}" etc. This will provide the required information.
Here is the source code for the cgi script mentioned above:
<BEGIN SOURCE CODE> #!/usr/bin/perl # If required, adjust line above to point to Perl 5. ###################################################### # (c) Copyright 2000 by fantomaster.com # # All rights reserved. # ######################################################
If your server's configuration does not permit execution of Perl or CGI scripts in the main directory (DocumentRoot), you may wish to try the following RewriteRule instead:
Quiz question: -------------- If we don't write "^216\.32\.64\." for a regular expression in the configuration above, but "^216\.32\.64" instead, will we get the identical effect, i.e. will this exclude the same IPs? =================================================
The regular expression ^216\.32\.64 will apply e.g. to the following strings:
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. 216.32.642.12 is not a valid IP. The only valid IP in the list above is 216.32.64.12!
Although the two regular expressions "^216\.32\.64\." and "^216\.32\.64" allow for different strings, due to the technical limitation of IP addresses to 0-255 this range of IPs will remain excluded.
(to be continued ...)
About the author :
Dirk Brockhausen is the co-founder and principal of fantomaster.com Ltd. (UK) and fantomaster.com GmbH (Belgium), a company specializing in webmasters software development, industrial-strength cloaking and search engine positioning services. He holds a doctorate in physics and has worked as an SAP consultant and software developer since 1994. He is also Technical Editor of fantomNews, a free newsletter focusing on search engine optimization, available at: < http://fantomaster.com/fantomnews-sub.html >
article_bot is posting articles from rss feeds on the internet. If you want article_bot to post to your forum click here
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=501