post Category: Code — Chris @ 4:26 am — post Comments (0)

For vanity search engine purposes i’ve written a script that re-directs a client request for http://cjbuckley.net/ to http://www.cjbuckley.net/. It’s important to do this so that google has one site index for your site, indeed, google honours 301 permanent re-directs for this very requirement!

The below script is written in Trafficscript language. What’s really useful about this script is that a client request for any URL not pre-fixed by www. is catenated and 301′d back to the server, prepended with the original path request.

# Cache Host header being issued by the client
$host = http.getHeader( "Host" );

# This line passes both the path and query string to $url,
# meaning that a request for /path/to/output?is-here.php
# is placed into the below variable.
$url = http.getRawURL();

# log.info( "url: ".$url ); #  Optional log output
# Use a Perl Compatible regular expression to match our domain name.
if( string.regexmatch( $host, "^domain-name$" ) ) {

# Re-write the variable cached in $host to include a prefix of 'www.'
$location = string.regexsub( $host, "domain-name.com", "www . ".$host );
http.sendResponse( "301 Moved Permanently", "text/html", "",
"Location: http://".$location . $url);
}

Sorry, no comments yet.

Write Your Comment

Comment Guidelines: Basic XHTML is allowed (a href, strong, em, code). All line breaks and paragraphs will be generated automatically.

You should have a name, right? 
Your email address, I promised I won't tell it to anyone. 
If you have a web site or blog, you can type the URL right here. 
This is where you type your comments. 
Remember my information for the next time I visit.
 

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 4 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a