Forum Discussion

Joe_Pipitone's avatar
Joe_Pipitone
Icon for Nimbostratus rankNimbostratus
Dec 23, 2009

Rewrite at the root of the domain

I have a rewrite rule that I'm already using to redirect the beginning of a domain request while keeping the URI as the user typed it in.

I want to redirect all requests to our-website.com/insert_uri_here to another-website.com/insert_uri_here

Will this work correctly? I need to make sure I catch all requests from the root as well as any other pages below so:

http://our-website.com/page.aspx rewrites to http://another-website.com/page.aspx, as well as http://our-website.com/

 
 when HTTP_REQUEST { 
    evaluate characters as lower case 
    Pass characters back to server in lower case 
   set my_uri [string tolower [HTTP::uri]] 
   if { $my_uri starts_with "/" } { 
      redirect to our-website.com/images on matching URI 
     HTTP::redirect http://another-website.com$my_uri 
   } 
  } 
 

I just want to make sure that the line if { $my_uri starts_with "/" } { is going to correctly catch these requests
  • Are you looking to only redirect based on the hostname? If so, you can issue the redirect like:

     
     HTTP::redirect http://another-website.com[HTTP::uri] 
     

    -Matt
  • Something else needs to happen too - I'm not sure this is possible?

     

     

    http://our-website.com (just the homepage) needs to redirect to http://another-website.com/portals/water.aspx

     

     

    Also, http://our-website.com/anyfolder/anypage.aspx needs to rewrite to http://another-website.com/anyfolder/anypage.aspx

     

     

    Any ideas? Thank you for any help!
  • Hi Joeseph,

    You could do the following

      
       when HTTP_REQUEST {   
          if { ([HTTP::host] eq "our-website.com") } {   
              switch -glob [string tolower [HTTP::uri]] {   
                   "/" { HTTP::redirect "http://another-website.com/portals/water.aspx" }   
                   default {  HTTP::redirect "http://another-website.com/[HTTP::uri]"   
              }   
           }   
       }   
       

    I hope this helps

    Bhattman
  • It does - but in the part of your rule where you are specifying /anyfolder/anypage.aspx, how can I catch any uri passed? Can I use set my_uri [string tolower [HTTP::uri]] somehow and then $my_uri?
  • Yes you can use my_uri. However, why create another variable when you don't need it - at least in the example I shown above.

     

     

     

    Bhattman
  • One question - it seems as though this rule is working, however if a user places a www in front of the domain name, it doesn't seem to catch it and redirect / rewrite:

     
     when HTTP_REQUEST {  
         if { ([HTTP::host] eq "old-site.com") } {  
             switch -glob [HTTP::uri] {  
                  "/" { HTTP::redirect "http://newsite.com/portals/water.aspx" }  
                  default {  HTTP::redirect "http://newsite.com[HTTP::uri]" } 
             }  
          }  
      } 
     

    old-site.com/someurl.aspx works, however www.old-site/someurl.aspx does not...

    Can anyone help?
  • The match is literal - you've used 'eq' here. So www.old-site.com != old-site.com. You can use 'contains' instead, which is greedier and should match both.

     

     

    -Matt