Forum Discussion
Irule - change 302 redirect iRule to a 301 redirect
I have the following 302 redirect iRule running, but i need to change it to a 301 redirect. I have a potential solution - would someone be able to verify it for me?
Existing rule: -
when HTTP_REQUEST {
set host [HTTP::host]
if { ($host ends_with "aaa.com") or
($host ends_with "bbb.com") or
($host ends_with "ccc.com") } {
set path [HTTP::path]
if { ($path starts_with "/one/") or
($path starts_with "/two/") } {
set newuri "https://$host[HTTP::uri]"
HTTP::redirect $newuri
}
}
}
New Rule: -
when HTTP_REQUEST {
set host [HTTP::host]
if { ($host ends_with "aaa.com") or
($host ends_with "bbb.com") or
($host ends_with "ccc.com") } {
set path [HTTP::path]
if { ($path starts_with "/one/") or
($path starts_with "/two/") } {
set newuri "https://$host[HTTP::uri]"
**_HTTP::respond 301 $newuri_**
}
}
}
1 Reply
- John_Alam_45640Historic F5 Account
The HTTP::redirect expects only the destination URL and it constructs a redirect for you.
So, for the HTTP::respond, you have to specify the "Location" header which normally contains the destination URL.
Here is how you do it:
HTTP::respond 301 Location $newuri
more examples here: https://devcentral.f5.com/wiki/iRules.HTTP__respond.ashx
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