Remove www before passing request to web server

Because of a licensing issue, we have to strip www. from the URL before passing it to the web server, if the user typed in www. So a request to www.mypage.com/blah/blah2… should get re-written mypage.com is parked… I tried a simple redirect, when HTTP_REQUEST { HTTP::redirect ] }, but that didn’t work at all. I think I can see why it wouldn’t work, but not sure how to do it. Thanks in advance.

Dave,

You have to add an if statement to determine when you want to redirect. Otherwise, as it is written, you are redirecting EVERY request so the browser gets stuck in an infinite redirect. Install a header plugin in your browser (like LiveHTTPHeaders for Firefox) and watch the headers and you’ll see what I mean. Try this.

when HTTP_REQUEST { 
   if { [HTTP::host] equals "www.mypage.com" }{ 
     HTTP::redirect http://mypage.com[HTTP::uri] 
   } 
 } 
 <\code> 
  
 Joe Martin

Thanks Joe. That fixed it.

when HTTP_REQUEST {

if { [HTTP::host] starts_with “www.”} {

HTTP::redirect ]

}

}