Forum Discussion
Heidi_35827
Nimbostratus
Nov 08, 2011iRule for HTTP redirect from retired URL to new URL
I'm new to iRules and could use some help. I think I have a pretty basic question but I'm not finding the answer after a few searches in DevCentral.
Here is what I'm trying to do....we have a web site that is retiring and will be replaced with a new site. We would like to do an http redirect to the new site when someone hits the old URL. Both sites are HTTPS. We want the URL in the users address bar to change to the new address.
Basic functionality: User goes to https://www.oldsite.com. Redirect is sent to send user to https://www.newsite.com
I've tried some basic HTTP redirect iRules, but none are working for me.
Do I need to use something other than a basic HTTP profile in the vserver I'm applying the iRule to?
Is the HTTPS adding some complexity that I'm not accounting for?
19 Replies
- Michael_Yates
Nimbostratus
Hi Heidi,
All that you should need is the basic default "http" HTTP Profile in order to apply an iRule to a Virtual Server.
The only thing that HTTPS is adding to your issue is that you can only apply one SSL Profile (which contains the SSL Certificate that the client will receive when they connect to the Virtual Server) per Virtual Server, so these two HTTPS Sites will have to be put on separate Virtual Servers to prevent SSL Certificate Mismatch Errors.
I made the assumption that these sites are not identical. Basically that https://www.oldsite.com/foo/bar/itemlist.html would NOT equal https://www.newsite.com/foo/bar/itemlist.html.
If they are, use the 2nd Example:when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "www.oldsite.com" } { HTTP::respond 301 Location "https://www.newsite.com" } } or when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "www.oldsite.com" } { HTTP::respond 301 Location "https://www.newsite.com[HTTP::uri]" } }
Hope this helps. - nathe
Cirrocumulus
Heidi
I take it your offloading the ssl transaction with a clientssl profile so the ltm can inspect the http traffic?
Here's an example of an irule I use for such things:
when HTTP_REQUEST {
if { [HTTP::host] equals "www.oldsite.com"} {
HTTP::redirect "www.newsite.com"
}
I'm also new to iruling but hoping to improve.
Hope it helps
N - nitass
Employee
HTTP::redirect returns 302. if it is permanent, using 301 may be better.
What's the difference between 301 redirects and 302 redirects
http://webdesign.about.com/od/http/qt/tip301v302redir.htm[root@ve1023:Active] config b virtual bar list virtual bar { snat automap destination 172.28.65.152:https ip protocol tcp rules myrule profiles { clientssl { clientside } http {} tcp {} } } [root@ve1023:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals "www.oldsite.com"} { HTTP::redirect "https://www.newsite.com[HTTP::uri]" } } } [root@ve1023:Active] config curl -Ik https://www.oldsite.com HTTP/1.0 302 Found Location: https://www.newsite.com/ Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve1023:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals "www.oldsite.com"} { HTTP::respond 301 Location "https://www.newsite.com[HTTP::uri]" } } } [root@ve1023:Active] config curl -Ik https://www.oldsite.com HTTP/1.0 301 Moved Permanently Location: https://www.newsite.com/ Server: BigIP Connection: Keep-Alive Content-Length: 0 - Heidi_35827
Nimbostratus
Thank you all for your help! I'm going to give these a try today, I'll let you know what works or what option I go with. - Heidi_35827
Nimbostratus
We are not doing SSL termination for this site. Could that be part of the issue? I realize we will get a cert error when using the old address, but the redirect should still work right?
I tried 2 variations of the above iRules with the same results. Both times, my vserver for www.newsite.com quit responding. It would not load the site either by using www.newsite.com or by using www.oldsite.com. When I would put the address in the browser, it would spin and spin, never loading a page. As soon as I removed the profile and iRule, the www.newsite.com began working again.
I modified the 443 vserver for www.newsite.com, selected the default http profile for that vserver, and then applied my iRule to the vserver. Here are the 2 iRules I tried....
iRule 1:
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "www.oldsite.com" } {
HTTP::respond 301 Location "https://www.newsite.com"
}
}
iRule 2:
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "www.oldsite.com" } {
HTTP::redirect "https://www.newsite.com"
}
} - nitass
Employee
We are not doing SSL termination for this site. Could that be part of the issue?ssl termination (clientssl profile) and http profile are needed since you need to parse http header and take an action accordingly. - Heidi_35827
Nimbostratus
OK, that makes sense. Thank you! - eyambej72_11653
Nimbostratus
need help with 301 redirect for this
Old URL: http://www.old.com/survey-solutions
New URL: http://new.com
thank you - Kevin_Stewart
Employee
Try this:when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "www.old.com" } { HTTP::respond 301 Location "http://new.com[HTTP::uri]" } } - eyambej72_11653
Nimbostratus
survey-solutions left out ?
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects