Forum Discussion
Redirect IP request to the name irule
Hi
Looks like you would be causing a redirect loop with the lines
elseif { ([HTTP::host] contains "10.10.10.15") } {
HTTP::redirect "https://[HTTP::host]/yyy"
as you're not changing the host to something other that the IP address.
Also, your call to check the host name of 10.10.10.15 is happening within the if statement to check for the host name of webserver.test.local. Move this logic to its own if statement.
Try this
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "webserver.test.local" } {
if { [HTTP::uri] equals "/" } {
HTTP::respond 301 Location "https://[HTTP::host]/yyy/"
#Stop processing further redirects
return
} elseif {
not ([HTTP::uri] contains "yyy") } {
HTTP::respond 301 Location "https://[HTTP::host]/yyy"
#Stop processing further redirects
return
}
}
if {
([HTTP::host] contains "10.10.10.15") } {
HTTP::respond 301 Location "https://webserver.test.local/yyy"
#Stop processing further redirects
return
}
#This will send all requests to this server, is this what you want?
node "10.20.1.15:4443"
}
You might also want to change these lines
not ([HTTP::uri] contains "yyy") } {
HTTP::respond 301 Location "https://[HTTP::host]/yyy"
to something like this where you check if /yyy is at the start of the uri to prevent legitimate calls to get redirect eg /something/something_else/yyy.jpg
not ([HTTP::uri] starts_with "yyy") } {
HTTP::respond 301 Location "https://[HTTP::host]/yyy[HTTP::uri]"
Also, if these links for /yyy and to the hostname are permanent, consider changing the HTTP status code to 301 (permanent) rather than 302 (temporary) as per my example above
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