Forum Discussion

rmangram_77953's avatar
rmangram_77953
Icon for Nimbostratus rankNimbostratus
Aug 14, 2013

Keeping only specific URI's from Redirecting

I am trying keep certain URI's from redirecting to a new site. Just to breakdown what I am trying to do:

 

  1. When the users Types in Oldsite.com, they are redirecting to a landingPage. This works fine via HTTP or HTTPS.
  2. If Users types in Oldsite.com/Marketing they are redirected to newsite.com/Marketing. This works fine via HTTP or HTTPS.3. If users are going to oldsite.com/teamsites/hr, oldsite.com/teamsites/finance, and oldsite.com/teamsites/it. I want them to stay to the oldsite and not be redirected to anywhere. They have to stay there until these pages are moved to the new site.
  3. If users types in oldsite.com/teamsites/ I want to redirect them to https://newsite.com/sites.

Here is my Irule Script below. Thanks

 

when HTTP_REQUEST { if { [string tolower [HTTP::host]] ends_with "oldsite.com" } { set uri [string tolower [HTTP::uri]] if { $uri equals "/" } { HTTP::respond 301 Location "https://landingpage.com"

 

} elseif { $uri starts_with "/teamsites/it/" or $uri starts_with "/teamsites/finance/" or $uri starts_with "/teamsites/hr/" } { if { [TCP::local_port] == 80 } { HTTP::respond 302 noserver Location "" } } else { HTTP::respond 302 noserver Location "" } } }

 

3 Replies

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus

    Here's my stab at this, cleaned it up with switch cmd. Not entirely sure if it's the best but here goes:

     

    when HTTP_REQUEST { if { [string tolower [HTTP::host]] ends_with "oldsite.com" } { set uri [string tolower [HTTP::uri]] switch $uri { "/" { HTTP::respond 301 Location "https://landingpage.com" } "/teamsites/" { HTTP::respond 301 Location "https://newsite.com/sites" } } switch -glob $uri { "/teamsites/it/" - "/teamsites/finance/" - "/teamsites/hr/*" { if { [TCP::local_port] == 80 } { HTTP::respond 302 noserver Location "https://[HTTP::host][HTTP::uri]" } } else { HTTP::respond 302 noserver Location "https://newsite.com[HTTP::uri]" } } } }

     

  • Ok Redirection works for the oldsite.com to the landingPage.com

     

    /Teamsites is not directing to the newsite.com/sites, this is still staying at the old site.

     

    switch -glob $uri { "/teamsites/it/" - "/teamsites/finance/" - "/teamsites/hr/*" This is working only for https, not Http.

     

    /teamsites/marketing is still going to oldsite and not the newsite.com/marketing(more like keeping the same directory.