Forum Discussion
Rewrite URL (301) when matches a certain condition
I want to forward traffic from my old site to my new one. They are not in the same data center so this might make it a bit more challenging.
DNS is going to be updated so that "; will get sent to the IP address for ";, when the traffic gets there I want it to meet with my iRule to rewrite the URL.
Presently I have tried something like this: when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "abc.def.com" { HTTP::respond 301 Location "https://zyx.wvu.com[HTTP::uri]" } }
I need this configured in such a way so as to preserve any of the trailing arguments. So if there is a "/something/landingpage.aspx" after the ".com" it needs to remain there, but the domain needs to be updated so that the URL will match and not cause the certificate to blow up.
What I have above does not appear to work, though I have tried to narrow down the rule as much as possible.
Any ideas would be appreciated as I am very new to F5 configuration.
HTTP::uri will keep path value as well as any parameters. See details https://devcentral.f5.com/wiki/iRules.HTTP__uri.ashx
For the following URL: http://www.example.com:8080/main/index.jsp?user=test&login=check The URI is: /main/index.jsp?user=test&login=check
I doubt you will need to redirect based on DNS IP. As long as there is DNS entry for zyx, redirect should work OK.
- Hannes_Rapp
Nimbostratus
Can you please open up Firefox debugger with F12, go to Network tab, and then visit "; ?
Then paste all request and response headers:
- initial request and response headers
and if it's there,
- request headers to final destination, ";
- jirish5563_3502
Nimbostratus
I was able to figure out part of the issue. The reason the iRule was not working was caused by the SSL Certificate. One site would have to redirect to the other and then the 301 can rewrite the URL. Because both of the Certs don't live on the F5 that was at least part of the issue.
The Rule that I setup, and is working, looks like this:
when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals "abc.def.com"} { HTTP::redirect "https://zyx.wuv.com[HTTP::uri]" } }
- Hannes_Rapp
Nimbostratus
Sweet. FYI,
function only does 302 redirects. For 301, you must useHTTP:redirect
HTTP::respond 301 Location "foo"
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