Forum Discussion

rmangram07_7795's avatar
rmangram07_7795
Icon for Nimbostratus rankNimbostratus
Jul 26, 2013

Redirecting Old Site to New Site Same Directory

I am new to irules and this seems straight forward but I cannot find the answer to this:

 

 

I have a site www.oldsite.com redirected to www.landingpage.com, and that works fine.

 

 

My issue is that anyone going to www.oldsite.com/directory needs to go to www.newsite.com/samedirectory(automatically). When I get the correct script can I add this to my existing script/irule?

 

 

Thanks for your help.

 

24 Replies

  • After testing this it appears that we only need certain directories to stay at oldsite.com and everything else go to newsite http or https. Keep in mind that the root oldsite.com is redirecting to the landginpage.com still. That is working fine

     

     

    when HTTP_REQUEST {

     

    if { [string tolower [HTTP::host]] equals "oldsite.com" } {

     

    set uri [string tolower [HTTP::uri]]

     

    if { $uri equals "/" } {

     

    HTTP::respond 301 Location "https://landingpage.com"

     

    } elseif { ($uri starts_with "/directory/it/") Stays on old site Getting an error on this line only..but I tried lol

     

    ($uri starts_with "/directory/hr/") Stays on old site

     

    ($uri starts_with "/directory/finance/") Stays on old site } {

     

    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]"

     

    }

     

    }

     

    }
  • After testing this it appears that we only need certain directories to stay at oldsite.com and everything else go to newsite http or https.not sure if i understand correctly. anyway, can you try this?

    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       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 "/directory/it/" or
          $uri starts_with "/directory/hr/" or
          $uri starts_with "/directory/finance/" } {
          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]"
        }
      }
    }
    }
    
  • The /Directory/hr or /Directory/it or /Directory/finance is going to the new site still this needs to stay on the oldsite.com. Everything else is working with the landing page.