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
Sort By
- Michael_Yates
Nimbostratus
Hi Heidi,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]" } }
- nathe
Cirrocumulus
Heidi - nitass
Employee
HTTP::redirect returns 302. if it is permanent, using 301 may be better.[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? - 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 - 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 ?
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