Forum Discussion
How to create an irule for below mentioned requirement
HI All,
Can some one help me creating an irule for below mentioned request.
301 permanent redirect
http://mydomain.testdomain.com/ o http://testdomain.com/mydomain/
http://abc.testdomain.com/ o http://testdomain.com/abc/
http://def.testdomain.com/ o http://testdomain.com/def/
http://testing.testdomain.com/ o http://testdomain.com/testing/
You could do something like this:
when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "mydomain.testdomain.com" { HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/mydomain/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } "abc.testdomain.com" { HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/abc/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } "def.testdomain.com" { HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/def/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } "testing.testdomain.com" { HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/testing/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } } }
or like this depending on how dynamic you'd like your iRule to be.
when HTTP_REQUEST { if { not ([HTTP::host] equals "testdomain.com") } { set myDomain [getfield [HTTP::host] "." 1] HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/$myDomain/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } }
- Brad_Parker_139Nacreous
You could do something like this:
when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "mydomain.testdomain.com" { HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/mydomain/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } "abc.testdomain.com" { HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/abc/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } "def.testdomain.com" { HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/def/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } "testing.testdomain.com" { HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/testing/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } } }
or like this depending on how dynamic you'd like your iRule to be.
when HTTP_REQUEST { if { not ([HTTP::host] equals "testdomain.com") } { set myDomain [getfield [HTTP::host] "." 1] HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/$myDomain/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } }
- Lakshmi_Sagar_SNimbostratusThanks Brad for your complete help :)
- Brad_Parker_139NacreousI would make the second rule like this to add the string tolower: when HTTP_REQUEST { if { not ([string tolower [HTTP::host]] equals "testdomain.com") } { set myDomain [getfield [HTTP::host] "." 1] HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/$myDomain/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } }
- Brad_Parker_139NacreousLet us know if one of these works out for you.
- Brad_ParkerCirrus
You could do something like this:
when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "mydomain.testdomain.com" { HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/mydomain/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } "abc.testdomain.com" { HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/abc/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } "def.testdomain.com" { HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/def/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } "testing.testdomain.com" { HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/testing/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } } }
or like this depending on how dynamic you'd like your iRule to be.
when HTTP_REQUEST { if { not ([HTTP::host] equals "testdomain.com") } { set myDomain [getfield [HTTP::host] "." 1] HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/$myDomain/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } }
- Lakshmi_Sagar_SNimbostratusThanks Brad for your complete help :)
- Brad_ParkerCirrusI would make the second rule like this to add the string tolower: when HTTP_REQUEST { if { not ([string tolower [HTTP::host]] equals "testdomain.com") } { set myDomain [getfield [HTTP::host] "." 1] HTTP::respond "HTTP/1.1 301 Moved Permanently\r\nLocation:http://testdomain.com/$myDomain/\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" } }
- Brad_ParkerCirrusLet us know if one of these works out for you.
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