Forum Discussion
Help on iRules
Hi Team,
I got a request to redirect one of my Website www.foods.com to www.drinks.com. In addition this when the website www.foods.com redirects to www.drinks.com user will get a message "You will be redirected to a different site"
How can i achieve the same with iRules.
3 Replies
- giltjr
Nimbostratus
Somebody needs to write the web page to display the message and do the redirect. You can display the page they write by doing:
set RedirectPage01 "html code goes here" if { ([string tolower [HTTP::host]] equals "www.foods.com") and ([HTTP::uri] equals "/")} { HTTP::respond 200 content $RedirectPage01 ; return } - giltjr
Nimbostratus
The "set" will set the value of the variable RedirectPage01 to what ever you put in between the quotes.
[string tolower [HTTP::host]] will covert the value of the variable HTTP::host to lower case. HTTP::host is a variable set by the F5 and it the value of the host header in the HTTP request.
([string tolower [HTTP::host]] equals "www.foods.com") will check to see if it is equal to www.foods.com.
([HTTP::uri] equals "/") will check to see if the URI is just plain "/", that is it is not "/somepage.html".
if { ([string tolower [HTTP::host]] equals "www.foods.com") and ([HTTP::uri] equals "/")} will check to see that both conditions are true and if they are both true the F5 will respond to the request sending the value of the variable RedirectPage01.
So if the host name is the check for host name will fail and the F5 will continue with any other logic in your iRule. If there is no other logic, then the F5 will pass the request through to the servers behind the F5 as configured.
If the hostname is but the URI is "/somepage.html", then the check for URI will fail and the F5 will continue with any other logic in your iRule. If there is no other logic, then the F5 will pass the request through to the servers behind the F5 as configured.
- StephanManthey
Nacreous
Hi MOHIT,
here is a solution to inform the client before forcing the browser to open the new page: Redirect a VS via irule Just replace the IP addresses in the example by the new name, i.e.:when HTTP_REQUEST { set page " The site has been retired. After 5 seconds, you will automatically be redirected to our new page at " HTTP::respond 200 content "${page}" Content-Type "text/html" }Thanks, Stephan
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