Forum Discussion
Redirect
I have a very simple redirect I want to create but can't seem to get my syntax correct.
All I want to do is redirect Http://website1 to http://website2
How do I do this with a simple iRule?
We are running BIG-IP 11.30 HF3
14 Replies
- Kevin_Stewart
Employee
Please try this:
when HTTP_REQUEST { HTTP::redirect "http://www.example.com" }Applying this iRule to a virtual server will cause ALL requests to be immediately redirected to the second host. This also assumes the two URLs are not hosted on the same virtual server.
- Debbie_123533
Nimbostratus
I'm confused, how will that redirect website1 to website2? This is what I have and it doesn't work:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "http://website1" } { HTTP::redirect "http://website2" } }
- Matt_Dierick
Employee
There is a mistake : HTTP:host is the host without the scheme.
http://website1 --> host = website1
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "website1" } { HTTP::redirect "http://website2" } } - Debbie_123533
Nimbostratus
THANK YOU! That worked!
- Debbie_123533
Nimbostratus
Oh but wait, I have a virtual directory underneanth website1/app1 that I don't want redirected. How do I do that? - Matt_Dierick
Employee
Check [HTTP:uri] as well. HTTP:host == website1 && HTTP:uri != app1
- Debbie_123533
Nimbostratus
I feel so stupid, but will that redirect app1 also? Here is my scenerio, I only need the main site of website1 redirected. Like this:
http://website1 = redirect to website2 http://website1/app1 - do not redirect http://website1/app2 - do not redirect etc... Can you tell me exactly what that rule would look like? Thanks!
- Matt_Dierick
Employee
No problem Debbie.
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "website1" && not ([string tolower [HTTP::uri]] starts_with "/app")} { HTTP::redirect "http://website2" } } - Debbie_123533
Nimbostratus
I'm getting the following error when I try to save this rule:
01070151:3: Rule [/Common/WisconsinFastForwardRedirect] error: line 1: [wrong args] [when HTTP_REQUEST ] line 2: [undefined procedure: if { [string tolower [HTTP::host]] equals "website1" && not ([string tolower [HTTP::uri]] starts_with "/app")} { HTTP::redirect "http://website2" } ] [{ if { [string tolower [HTTP::host]] equals "website1" && not ([string tolower [HTTP::uri]] starts_with "/app")} { HTTP::redirect "http://website2" } }]
- rob_carr
Cirrocumulus
Try putting the opening brace on the same line as 'when HTTP_REQUEST', and make sure that you have the right number of closing braces.
- Matt_Dierick
Employee
Copy / paste issue from Devcentral.
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "website1" && not ([string tolower [HTTP::uri]] starts_with "/app")} { HTTP::redirect "http://website2" } }Copy and paste this line 😉
- Debbie_123533
Nimbostratus
Thank you for your help but it's not quite working. My website1 is being redirected but when I go to http://website1/app1 "Internet Explorer cannot display the webpage"
- Matt_Dierick
Employee
Humm, try this
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "website1" && not ([string tolower [HTTP::uri]] starts_with "/app")} { HTTP::redirect "http://website2" } else { return } }But be careful. All objects in /app must stay in /app in your website. Else objects will be redirected to website2.
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