Forum Discussion
Silver_back
Feb 08, 2022Altostratus
URL redirect with path
I am trying to create a redirect irule but is not a standard redirect. It basically needs to take the URL + path and redirect it to another website + the path of the old URL. E.g. www.abc.com/path1/...
JRahm
Feb 08, 2022Admin
A couple comments/questions...
- All URLs start with "/", so as long as the host is www.abc.com, you'll never get to the else.
- There is no need to string tolower the host, that is case insensitive according to the RFC.
- Do you want any redirects if the host is not www.abc.com? If it's not, there is no additional logic to handle that.
That said, assuming you don't need any redirects for the non-matching host, here's how I'd write that:
when HTTP_REQUEST {
if { ([HTTP::host] eq "www.abc.com") and not([HTTP::uri] eq "/") } {
HTTP::respond 301 Location "http://jrahmtest.local[HTTP::uri]"
event disable all
} elseif { [HTTP::host] eq "www.abc.com" } {
HTTP::respond 301 Location "http://jrahmtest.local/"
event disable all
}
}
Test results:
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects