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.

what is the existing irule? can you try something like this?

e.g.

[root@ve11a:Active:Changes Pending] config  tmsh list ltm virtual bar
ltm virtual bar {
    destination 172.28.20.111:80
    ip-protocol tcp
    mask 255.255.255.255
    pool foo
    profiles {
        http { }
        tcp { }
    }
    rules {
        myrule
    }
    source 0.0.0.0/0
    source-address-translation {
        type automap
    }
    vlans-disabled
}
[root@ve11a:Active:Changes Pending] config  tmsh list ltm rule myrule
ltm rule myrule {
    when HTTP_REQUEST {
  if { [HTTP::host] eq "www.oldsite.com" } {
    HTTP::respond 302 noserver Location "http://www.newsite.com[HTTP::uri]"
  }
}
}

[root@ve11a:Active:Changes Pending] config  curl -I http://172.28.20.111/something -H "Host: www.oldsite.com"
HTTP/1.0 302 Found
Location: http://www.newsite.com/something
Connection: Keep-Alive
Content-Length: 0

Thanks that works, now how can I combine the two together? Right now I have two Irule scripts:

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

Second Irule

when HTTP_REQUEST { 
if { [string tolower [HTTP::host]] equals "oldsite.com" } { HTTP::respond 302 noserver Location "https://newsite.com[HTTP::uri]" }
}

When I put the both Irules, one takes over the other and I need them to work together.

Thanks

how can I combine the two together?can you try this?

e.g.

[root@ve10:Active] config  b virtual bar list
virtual bar {
   snat automap
   pool foo
   destination 172.28.19.252:80
   ip protocol 6
   rules myrule
   profiles {
      http {}
      tcp {}
   }
}
[root@ve10:Active] config  b rule myrule list
rule myrule {
   when HTTP_REQUEST {
  if { [string tolower [HTTP::host]] equals "oldsite.com" } {
    if { [string tolower [HTTP::uri]] equals "/" } {
      HTTP::respond 302 noserver Location "https://landingpage.com"
    } else {
      HTTP::respond 302 noserver Location "https://newsite.com[HTTP::uri]"
    }
  }
}
}

 test

[root@ve10:Active] config  curl -I http://172.28.19.252 -H "Host: oldsite.com"
HTTP/1.0 302 Found
Location: https://landingpage.com
Connection: Keep-Alive
Content-Length: 0

[root@ve10:Active] config  curl -I http://172.28.19.252/something -H "Host: oldsite.com"
HTTP/1.0 302 Found
Location: https://newsite.com/something
Connection: Keep-Alive
Content-Length: 0

Ok one last question, you guys are great! If I want the users to stay at the old site for example:

http://oldsite/it/useradmin/\* redirect to https://oldsite/it/useradmin/\*

and https://oldsite/it/useradmin/\* redirect to https://oldsite/it/useradmin/\*

I have other links that is going to come from other app owners that wants to stay within the old site and keep users there until they move the content over to the new site.

Ok one last question, you guys are great! If I want the users to stay at the old site for example:

http://oldsite.com/it/useradmin/\* redirect to https://oldsite.com/it/useradmin/\*

and https://oldsite.com/it/useradmin/\* redirect to https://oldsite.com/it/useradmin/\*

I have other links that is going to come from other app owners that wants to stay within the old site and keep users there until they move the content over to the new site.

I have other links that is going to come from other app owners that wants to stay within the old site and keep users there until they move the content over to the new site.is it something like this?

e.g.

[root@ve10:Active] config  b virtual bar list
virtual bar {
   snat automap
   pool foo
   destination 172.28.19.252:80
   ip protocol 6
   rules myrule
   profiles {
      http {}
      tcp {}
   }
}
[root@ve10:Active] config  b rule myrule list
rule myrule {
   when HTTP_REQUEST {
  if { [string tolower [HTTP::host]] equals "oldsite.com" } {
    set uri [string tolower [HTTP::uri]]
    if { $uri equals "/" } {
      HTTP::respond 302 noserver Location "https://landingpage.com"
    } elseif { not ($uri starts_with "/it/useradmin/") } {
      HTTP::respond 302 noserver Location "https://newsite.com[HTTP::uri]"
    }
  }
}
}

[root@ve10:Active] config  curl -I http://172.28.19.252 -H "Host: oldsite.com"
HTTP/1.0 302 Found
Location: https://landingpage.com
Connection: Keep-Alive
Content-Length: 0

[root@ve10:Active] config  curl -I http://172.28.19.252/something -H "Host: oldsite.com"
HTTP/1.0 302 Found
Location: https://newsite.com/something
Connection: Keep-Alive
Content-Length: 0

[root@ve10:Active] config  curl -I http://172.28.19.252/it/useradmin/something -H "Host: oldsite.com"
HTTP/1.1 404 Not Found
Date: Tue, 06 Aug 2013 04:26:09 GMT
Server: Apache/2.2.3 (CentOS)
Content-Type: text/html; charset=iso-8859-1

The script that I have working right now is the one dated 8/1/13, the redirection will still stay the same. Now we have customers that we will need to keep on the old site like you mentioned, how can I add this to the existing script:

This works great but I need to add that script above to this..

When HTTP Request { 
if { [string tolower [HTTP::host]] equals "oldsite.com" } { 
if { [string tolower [HTTP::uri]] equals"/" } { 
HTTP::respond 301 Location "https://landingpage.com" 

} else { 
HTTP::respond 302 noserver Location "https://newsite.com[HTTP::uri]" 
} 
} 
}

I need to add that script above to this.. actually, it is already added. since it does nothing on “/it/useradmin/”, i collapses it by using 'not". the following is when not using “not”.

when HTTP_REQUEST {
  if { [string tolower [HTTP::host]] equals "oldsite.com" } {
    set uri [string tolower [HTTP::uri]]
    if { $uri equals "/" } {
      HTTP::respond 302 noserver Location "https://landingpage.com"
    } elseif { $uri starts_with "/it/useradmin/" } {
       do nothing
    } else {
      HTTP::respond 302 noserver Location "https://newsite.com[HTTP::uri]"
    }
  }
}

Awesome, let me try this out and will keep you updated. Thanks!

for http://www.oldsite.com/it it does not work but for https:///www.oldsite.com/it it works. Can I get a redirect added to this script to make sure that users are redirected to the site. Right now just comes up with page not found.

I actually put a /it/* to accept everything after that. That tends to work fine.

Also as I am testing if a user goes to http://ww.oldsite.com it redirects them https://landingpage.com but if they go to https://ww.oldsite.com they stay at oldsite.com. I need them to go to landingpage.com as well.

for http://www.oldsite.com/it it does not work i thought you want “/it/useradmin/*”. if it is “/it/*”, you can just change from “/it/useradmin/” to “/it/” in the irule.

if they go to https://ww.oldsite.com they stay at oldsite.com. I need them to go to landingpage.com as well. i understand you have 2 virtual servers; one is 80 and the other one is 443, haven’t you? what irule do you apply to 443 virtual server?

e.g.

[root@ve10:Active] config  b virtual bar80 list
virtual bar80 {
   snat automap
   pool foo
   destination 172.28.19.252:80
   ip protocol 6
   rules myrule
   profiles {
      http {}
      tcp {}
   }
}
[root@ve10:Active] config  b virtual bar443 list
virtual bar443 {
   snat automap
   pool foo
   destination 172.28.19.252:443
   ip protocol 6
   rules myrule
   profiles {
      clientssl {
         clientside
      }
      http {}
      tcp {}
   }
}
[root@ve10:Active] config  b rule myrule list
rule myrule {
   when HTTP_REQUEST {
  if { [string tolower [HTTP::host]] equals "oldsite.com" } {
    set uri [string tolower [HTTP::uri]]
    if { $uri equals "/" } {
      HTTP::respond 302 noserver Location "https://landingpage.com"
    } elseif { not ($uri starts_with "/it/") } {
      HTTP::respond 302 noserver Location "https://newsite.com[HTTP::uri]"
    }
  }
}
}

 http

[root@ve10:Active] config  curl -I http://172.28.19.252/ -H "Host: oldsite.com"
HTTP/1.0 302 Found
Location: https://landingpage.com
Connection: Keep-Alive
Content-Length: 0

[root@ve10:Active] config  curl -I http://172.28.19.252/something -H "Host: oldsite.com"
HTTP/1.0 302 Found
Location: https://newsite.com/something
Connection: Keep-Alive
Content-Length: 0

[root@ve10:Active] config  curl -I http://172.28.19.252/it/something -H "Host: oldsite.com"
HTTP/1.1 404 Not Found
Date: Thu, 08 Aug 2013 01:47:16 GMT
Server: Apache/2.2.3 (CentOS)
Content-Type: text/html; charset=iso-8859-1

 https

[root@ve10:Active] config  curl -Ik https://172.28.19.252/ -H "Host: oldsite.com"
HTTP/1.0 302 Found
Location: https://landingpage.com
Connection: Keep-Alive
Content-Length: 0

[root@ve10:Active] config  curl -Ik https://172.28.19.252/something -H "Host: oldsite.com"
HTTP/1.0 302 Found
Location: https://newsite.com/something
Connection: Keep-Alive
Content-Length: 0

[root@ve10:Active] config  curl -Ik https://172.28.19.252/it/something -H "Host: oldsite.com"
HTTP/1.1 404 Not Found
Date: Thu, 08 Aug 2013 01:47:33 GMT
Server: Apache/2.2.3 (CentOS)
Content-Type: text/html; charset=iso-8859-1

The same Irule is applied for the 443 VS as well.

Sorry Disregard that last statement

Sorry Disregard that last statement, I did not have an I rule applied to it. I am testing this out the whole scenario now.

Ok everything is working now except..

When I got to http://www.oldsite.com/it..it does not redirect to https://www.oldsite.com/it.

But it does work only with https://www.oldsite.com/it. So it stays at the old site.

can you try this please?

[root@ve10:Active] config  b rule myrule list

rule myrule {

   when HTTP_REQUEST {

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

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

    if { $uri equals "/" } {

      HTTP::respond 302 noserver Location "https://landingpage.com"

    } elseif { $uri starts_with "/it/" } {

      if { [TCP::local_port] == 80 } {

        HTTP::respond 302 noserver Location "https://oldsite.com[HTTP::uri]"

      }

    } else {

      HTTP::respond 302 noserver Location "https://newsite.com[HTTP::uri]"

    }

  }

}

}

Still no go for http://www.oldsite.com/it.. goes to new site still.. Here is what I have…

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 “/it/”) } {

if { [TCP::local_port] == 80 } {

HTTP::respond 302 no server Location “https://oldsite.com[HTTP::uri]”

}

} else {

HTTP::respond 302 noserver Location “https://newsite.com[HTTP::uri]”

}

}

}

Still no go for http://www.oldsite.com/it.. goes to new site still.. Here is what I have…

oops i just notice it is www.oldsite.com (not oldsite.com). so, can you try this?

when HTTP_REQUEST {

if { [string tolower [HTTP::host]] ends_with “oldsite.com” } {

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

if { $uri equals “/” } {

HTTP::respond 302 noserver Location “https://landingpage.com”

} elseif { $uri starts_with “/it/” } {

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

}

}

}