Forum Discussion
Is it possible to use an LTM Policy for sending 301 redirects?
Am experimenting with Policies. Hoping it is possible to send 301 redirects with a Policy.
11 Replies
- Kevin_Stewart
Employee
An LTM policy redirect will only send a 302. You'll need an iRule to send a 301.
when HTTP_REQUEST { if { something } { HTTP::respond 301 Location "somewhere" } } - OTS02
Cirrus
Thanks Kevin. Maybe in future releases? Sure would be nice to replace my iRule (with ever growing number of vanity redirects) with a Policy, since it does not have as much performance impact.
BTW, how do I get the Policy to do a 302? I monkeyed around with it, but couldn't arrive at the correct combination.
- Stanislas_Piro2
Cumulonimbus
Hi,
to do a 302, you must configure:
- policy control : forwarding
- rule action : http-reply redirect
- OTS02
Cirrus
Thanks!
- writemike
Nimbostratus
Does anyone know if version 12 LTM Policies allow 301 redirects? Or if this feature has been roadmaped for a future release?
- Stanislas_Piro2
Cumulonimbus
Hi,
If you want to define redirect from Local traffic policy, you can add a tcl variable in policy rule and add this irule executing the redirect...
Redirect from Local Traffic Policy to use it, create an action tcl set variable - name : Redirect - expression : Redirect URL when HTTP_REQUEST { if {([info exists "Redirect"])} { HTTP::respond 301 Location $Redirect return } } - OTS02
Cirrus
Stanislas, that is so cool - thanks!
- Steve_Dionne
Nimbostratus
Awesome! Thank Stanislas.
- Steve_Dionne
Nimbostratus
Your should create only one LTM Policy that will contains only one Rule.
The Variable Redirect will contains the actual url to be redirected.
The iRule will read the variable Redirect and will redirect to that URL
In my case I redirect to HTTPS. You create a Virtual Server, and Assign the Policy and the iRule. Policy is read first and then the iRule will contains a value for the Redirect Variable.
- Steve_Dionne
Nimbostratus
ltm policy http2httpsredirect_301_pol { last-modified 2017-01-19:10:44:32 requires { http } rules { http2httpsredirect_301_rule { actions { 0 { tcl set-variable expression "https://[getfield [HTTP::host] \":\" 1][HTTP::uri]" name Redirect } } conditions { 0 { http-uri port values { 80 } } } } } status published strategy first-match }then the iRule is like this:
ltm rule redirect_from_local_traffic_policy_301_irule { Redirect from Local Traffic Policy to use it, create an action tcl set variable - name : Redirect - expression : Redirect URL when HTTP_REQUEST { if {([info exists "Redirect"])} { HTTP::respond 301 Location $Redirect return } } } - Gail_K_174408
Nimbostratus
Thank you Steve!
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