Forum Discussion
Create 2 different iRules for Redirection
Hi Experts,
In below irule1 , www. gets added to the beginning of the URI , with few exceptions
when HTTP_REQUEST {
if {not ([HTTP::host] starts_with "www") and not ([HTTP::host] equals "myownwork.com" )}
{
HTTP::redirect "http://www.[HTTP::host][HTTP::uri]"
}
}
My requirement is :
1) The no of websites for which i would not like to prefix "WWW" has increased , hence exempting in a single rule becomes difficult (the above is just an example , there are many more URLS in this single iRule1 , making it look very complicated).Can i use data group list for these websites and list all the URLS under that ? If yes , kindly let me know an example for same by modifying above iRule1.
2) I want to create a separate iRule2 for few URLS (Some of these URLS are websites exempted in iRule1) . For these URLS , i would like www. added to the beginning of the URI as well as redirection to another Parent URL .The reason for a seperate iRule is that both these conditions will make it a single Redirection iRule .Refer iRule2 below :
when HTTP_REQUEST {
if {not ([HTTP::host] starts_with "www") and ([HTTP::host] equals "myownwork.com" )}
{
HTTP::redirect "http://www.yourwork.com"
}
}
a) In the above iRule , i want to add "string tolower " before 2nd condition of HTTP::host , please help in getting this added.
b) In this iRule , I also want to ensure that if the user typed www.myownwork.com in the browser , then also it should get redirected to http://www.yourwork.com
Note : Both these iRules needs to be added in the same Virtual server with the iRule 1 would come first , followed by iRule 2.
Regards,
Ankur
8 Replies
- Kevin_Stewart
Employee
I think you could get away with doing something much simpler. For example, let's say you have a data group filled with domain names.
ltm data-group internal domlist { records { herownwork.com { } hisownwork.com { } myownwork.com { } thatownwork.com { } thisownwork.com { } } type string }Then the iRule might look something like this:
when HTTP_REQUEST { if { not ( [string tolower [HTTP::host]] starts_with "www." ) } { if { [class match [string tolower [HTTP::host]] equals domlist] } { host in the list - issue redirect to parent URL HTTP::redirect "http://www.yourwork.com" } else { host not in data group - redirect to self and add www. HTTP::redirect "http://www.[HTTP::host][HTTP::uri]" } } } - Ankur_5273
Nimbostratus
Hi Kevin
Thanks a lot for the update , but in iRule1 there is one domain for which "www" is not at all required eg: workplace.yourwork.com , kindly suggest how to accommodate it in the same iRule as you mentioned above .
- Ankur_5273
Nimbostratus
Hi Kevin
Thanks a lot and the above irule works fine !! However there is one issue :
--> myownwork.com gets redirected to http://www.yourwork.com
(myownwork.com is listed under Data group list)
--> www.myownwork.com doesnot gets redirected to http://www.yourwork.com and opens up as itself (www.myownwork.com)
Please suggest what could be done so that on browsing myownwork.com OR www.myownwork.com , it redirects to http://www.yourwork.com
- Ankur_5273
Nimbostratus
Hi Experts
Can anyone please assist on this ?
Regards, Ankur
- Kevin_Stewart
Employee
Perhaps this:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] ends_with "myownwork.com" } { HTTP::redirect "http://www.yourwork.com" } elseif { not ( [string tolower [HTTP::host]] starts_with "www." ) } { if { [class match [string tolower [HTTP::host]] equals domlist] } { host in the list - issue redirect to parent URL HTTP::redirect "http://www.yourwork.com" } else { host not in data group - redirect to self and add www. HTTP::redirect "http://www.[HTTP::host][HTTP::uri]" } } } - Ankur_5273
Nimbostratus
Hi Kevin
The above doesnot work as per my requirement . I will give a quick recap again . Any URL falling under data group whether with "www" or without "www" should get redirected to parent URL http://www.yourwork.com . But any Other URL (not falling under data group and NOT starting with www , as well as not beginning with "myworkplace") should have just "www" append at the begining of the URL
I have modified your previous iRule as follows , please check this if it makes sense and also help in correcting the syntax :
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] starts_with "www." } { if { [class match [string tolower [HTTP::host]] equals domlist] } { host in DG list but user types full URL www.myownwork.com - issue redirect to parent URL HTTP::redirect "http://www.yourwork.com" } elseif { not ( [string tolower [HTTP::host]] starts_with "www." and not ([string tolower[HTTP::host]] starts_with "myworkplace") } { if { [class match [string tolower [HTTP::host]] equals domlist] } { host in DG list but user doesnt type full URL myownwork.com - issue redirect to parent URL HTTP::redirect "http://www.yourwork.com" } else { host not in data group - redirect to self and add www. HTTP::redirect "http://www.[HTTP::host][HTTP::uri]" } }}
- Ankur_5273
Nimbostratus
Hi Kevin,
Kindly suggest on my query
Thanks and Regards, Ankur
- Kevin_Stewart
Employee
Okay, this should be closer to your description:
when HTTP_REQUEST { if { [class match [string tolower [HTTP::host]] ends_with my_uri_dg] } { in the data group HTTP::respond 302 Location "http://www.yourwork.com" } else { not in the data group if { not ( [string tolower [HTTP::host]] starts_with "www." ) and not ( [string tolower [HTTP::host]] starts_with "myworkplace" ) } { not in datagroup, not start with www and not start with myworkplace HTTP::redirect "http://www.[HTTP::host][HTTP::uri]" } else { doesn't match any conditions return } } }
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