Layer47 forum Homepage
Forum Home Forum Home > jetNEXUS Products > jetNEXUS Enterprise range > Traffic Scripting
  New Posts New Posts
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Simple URL Redirect

 Post Reply Post Reply
Author
Message
  Topic Search Topic Search  Topic Options Topic Options
jakevs View Drop Down
Newbie
Newbie
Avatar

Joined: 11 Jan 2010
Location: Marlow
Online Status: Offline
Posts: 2
  Quote jakevs Quote  Post ReplyReply Direct Link To This Post Topic: Simple URL Redirect
    Posted: 11 Jan 2010 at 12:00pm
Hi guys

This is probably a silly thing to ask, but it would be useful to have it in a forum like this (especially since I don't play with our ZXTM on a daily basis)

What should my traffic script look like if I want to forward requests that are sent to e.g. http://whatever.com to http://www.whatever.com?

My current script looks like this:
if( http.getheader( "host" ) == "whatever.com" ){

            http.redirect( "http://www.whatever.com" );

}

Thanks
Jake

Edited by jakevs - 11 Jan 2010 at 12:16pm

--------------------
jetNEXUS ZXTM v4.1r3
IIS 6.0
--------------------
Back to Top
jakevs View Drop Down
Newbie
Newbie
Avatar

Joined: 11 Jan 2010
Location: Marlow
Online Status: Offline
Posts: 2
  Quote jakevs Quote  Post ReplyReply Direct Link To This Post Posted: 11 Jan 2010 at 12:13pm
Hi again,

Some clarification on what I meant...

Can I have a generic rule that I can apply to all my virtual servers (i.e. not having to specify the domain name in the rule?

Thank you

Jake
What should my traffic script look like if I want to forward requests that are sent to e.g. http://whatever.com to http://www.whatever.com?


Edited by jakevs - 11 Jan 2010 at 12:13pm

--------------------
jetNEXUS ZXTM v4.1r3
IIS 6.0
--------------------
Back to Top
JonathanDade View Drop Down
Admin Group
Admin Group


Joined: 23 Sep 2008
Online Status: Offline
Posts: 2
  Quote JonathanDade Quote  Post ReplyReply Direct Link To This Post Posted: 14 Jan 2010 at 10:28am
var gaJsHost = (("https:" == document.location.protocol) ?"https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); Hi Jake,
 
We liked this question, here in the Layer 47 Geek Farm. So we started working on it.
 
What we thought was to be genuinely generic it would need to handle more than just adding the new hostname on the beginning. What if the request was SSL or if there is a query string?
 
Here is what we finally came up with:

##
# Redirect a request from a domain to the www host
##

#
# Don't run the script if the host is already www......
#
if ( string.startsWith( http.getHostHeader(), "www." ) )
{
  break;
}
#
# Get the request parts needed
#
$host = "www.".http.getHostHeader();
$path = http.getPath();
$query = http.getRawQueryString();
#
# Checking the protocol from the client
#
if ( ssl.isSSL() )
{
  $protocol = "https://";
} else {
  $protocol = "http://";
}
#
# Define the location string ready for the redirect
#
$location = "Location: ".$protocol.$host.$path;
#
# Check if there is a query string in the request
#
if ( $query != "" )
{
  $location = $location."?".$query;
}
#
# Send the client to the right place
#
http.sendResponse( "301 Moved Permanently", "text/html", "", $location );
 
I hope this helps.
< ="http://www.google-analytics.com/ga.js" =text/> try { var pageTracker = _gat._getTracker("UA-491206-7"); pageTracker._trackPageview(); } catch(err) {}
Jonathan Dade
Technical Services Manager
jetNEXUS Solutions
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.51
Copyright ©2001-2008 Web Wiz