Forum Discussion
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:
- When the users Types in Oldsite.com, they are redirecting to a landingPage. This works fine via HTTP or HTTPS.
- 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.
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
Cirrocumulus
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]" } } } }
- rmangram_77953
Nimbostratus
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.
- rmangram_77953
Nimbostratus
Any more suggestions would be appreciated..
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com