Transparently redirecting clients from http://domain.com/ to http://www.domain.com/

Here's how to accomplish vanity domain names within ZXTM. Many popular websites will respond to a http://domain-name.com/ request, but will issue a 301 re-direct to http://www.domain-name.com/. Let's demonstrate how ZXTM can quickly and easily accommodate this requirement, including transparently re-writing any URL 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 );
# Issue a permanent re-direct to the client (Google requires a 301 response code to
# ensure a request for http://domain-name/ is included within
http.sendResponse( "301 Moved Permanently", "text/html", "",
# Catenate the newly created $location variable with the original $url query request
"Location: http://".$location.$url);
}

Here's our final trafficscript in full vim syntax glory:

Chris Buckley [Zeus Support] 04 August 2006 1 comment  

Comments:

This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.

Comment from: vinny foreman [Visitor] · http://www.redheadmedia.co.uk
Hi I'm trying to achieve the above on a site that is hosted on a Zeus server. I'm not able to use the .htaccess file. I have tried the above script but it doesn't work. I have searched a great length on the internet for an answer to this question and have found a number of solution, none of which work.

1. Can someone please tell me how to achieve a simple 301 redirect from non www to www equivalent.
2. what file should this be in and where
3. are there any necessary permissions on this file

thanks
Vinny
Permalink 08 July 2008 @ 20:44
Leave a comment ...
Your email address will not be displayed.
Your URL will be displayed.
This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)
www.zeus.com

Recently...

Other Resources