# Redirect 302 with aFlex

**URL:** <https://community.a10networks.com/t/redirect-302-with-aflex/726>\
**Category:** aFleX\
**Tags:** redirect\
**Created:** [June 7, 2022, 3:32pm UTC](https://community.a10networks.com/t/redirect-302-with-aflex/726 "2022-06-07T15:32:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rodrigosh](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@rodrigosh](https://community.a10networks.com/u/rodrigosh)\
**Post date:** [June 7, 2022, 3:32pm UTC](https://community.a10networks.com/t/redirect-302-with-aflex/726/1 "2022-06-07T15:32:01Z")

</div>

Hello, I need your help and knowledge on A10 with aFlex.  
I am trying to create a 302 redirect for a site that is published on the internet but when testing the redirect it does not execute it, this is my code so that you can guide me:  
when HTTP\_REQUEST {  
&nbsp; &nbsp; &nbsp;if {[HTTP::host] == "[https://recargaweb.imperial.com/"](https://recargaweb.movistar.cl/%22) } {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HTTP::respond 302 Location "[https://recargaweb.imperial.com/publico"](https://recargaweb.movistar.cl/publico%22)  
&nbsp;&nbsp;&nbsp;}  
}

---

<div class="post-metadata">

**Author:** ![invia\_itops](https://avatars.discourse-cdn.com/v4/letter/i/b5ac83/32.png) [@invia\_itops](https://community.a10networks.com/u/invia_itops)\
**Post date:** [June 7, 2022, 5:25pm UTC](https://community.a10networks.com/t/redirect-302-with-aflex/726/2 "2022-06-07T17:25:43Z")

</div>

Host does not contain the protocol or /, just using [recargaweb.imperial.com](https://recargaweb.imperial.com/%22) should work.

---

<div class="post-metadata">

**Author:** ![boteye](https://avatars.discourse-cdn.com/v4/letter/b/8797f3/32.png) [@boteye](https://community.a10networks.com/u/boteye)\
**Post date:** [June 7, 2022, 5:26pm UTC](https://community.a10networks.com/t/redirect-302-with-aflex/726/3 "2022-06-07T17:26:44Z")

</div>

Please try below:  
when HTTP\_REQUEST {  
if { [HTTP::host] equals “[recargaweb.imperial.com](http://recargaweb.imperial.com)” } {  
HTTP::redirect "https://[HTTP::host]/publico"&nbsp;  
}  
I have tested this script and the results are as below

 ![aflex-test.jpg](https://us1.discourse-cdn.com/flex002/uploads/a10_community/original/1X/fbd7773e2afdb0d2c6fd1967e70da3e29fe75494.jpeg)

---

<div class="post-metadata">

**Author:** ![rodrigosh](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@rodrigosh](https://community.a10networks.com/u/rodrigosh)\
**Post date:** [June 7, 2022, 5:30pm UTC](https://community.a10networks.com/t/redirect-302-with-aflex/726/4 "2022-06-07T17:30:35Z")

</div>

Apparently I must remove HTTPS from the host, although the ACOS system does not claim me for entering that protocol.  
It worked for me this way:  
when HTTP\_REQUEST {  
if {[HTTP::host] matches “[recargaweb.imperial.com](http://recargaweb.imperial.com)” and [HTTP::uri] matches “/”} {

# [HTTP::host] “[recargaweb.imperial.com](http://recargaweb.imperial.com)”

HTTP::uri /publico  
}  
}  
Anyway, I’m going to try the possibilities that were indicated to me… thank you very much

---

<div class="post-metadata">

**Author:** ![invia\_itops](https://avatars.discourse-cdn.com/v4/letter/i/b5ac83/32.png) [@invia\_itops](https://community.a10networks.com/u/invia_itops)\
**Post date:** [June 7, 2022, 5:32pm UTC](https://community.a10networks.com/t/redirect-302-with-aflex/726/5 "2022-06-07T17:32:27Z")

</div>

You can also just use HTTP Policy instead, no need for an aflex in this case.

---

<div class="post-metadata">

**Author:** ![rodrigosh](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@rodrigosh](https://community.a10networks.com/u/rodrigosh)\
**Post date:** [June 7, 2022, 5:37pm UTC](https://community.a10networks.com/t/redirect-302-with-aflex/726/6 "2022-06-07T17:37:00Z")

</div>

If you tried to redirect with an HTTP policy, but the site did not load, it indicated that it has been redirected many times in the browser.

---

<div class="post-metadata">

**Author:** ![boteye](https://avatars.discourse-cdn.com/v4/letter/b/8797f3/32.png) [@boteye](https://community.a10networks.com/u/boteye)\
**Post date:** [June 7, 2022, 5:38pm UTC](https://community.a10networks.com/t/redirect-302-with-aflex/726/7 "2022-06-07T17:38:54Z")

</div>

The expression for the “If” statement you mentioned is accurate. [HTTP::uri] equals “/” is required to avoid going into an infinite loop.
