# Redirect  when HTTP\_RESPONSE \[HTTP::status\] contains "200"

**URL:** <https://community.a10networks.com/t/redirect-when-http-response-http-status-contains-200/387>\
**Category:** aFleX\
**Tags:** aflex\
**Created:** [April 29, 2016, 2:05pm UTC](https://community.a10networks.com/t/redirect-when-http-response-http-status-contains-200/387 "2016-04-29T14:05:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leandro](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@Leandro](https://community.a10networks.com/u/Leandro)\
**Post date:** [April 29, 2016, 2:05pm UTC](https://community.a10networks.com/t/redirect-when-http-response-http-status-contains-200/387/1 "2016-04-29T14:05:48Z")

</div>

I need to set up a script that does redirection when there was status code 200 for the same page with dynamic context for example [https://myURL.com/xtyfwdk](https://myURL.com/xtyfwdk)

I set the following script but has error

Error : aFleX compile error : line 15: “command is invalid in current event context [HTTP :: uri]”  
used script

```auto
When HTTP\_RESPONSE \{
if \{ [HTTP :: Status] contains " 200 "\} \{
HTTP :: redirect " https://myurl.com[HTTP::uri]"
\}
\}

```

But when I set for a Static page works

```auto
When HTTP\_RESPONSE \{
if \{ [HTTP :: Status] contains " 200 "\} \{

```

HTTP :: redirect " [https://myurl.com/project/](https://myurl.com/project/) "

```auto
\}
\}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/a10_community/original/1X/bb9f186d33804d3044a0374e589f49fdf3be1328.png) [@system](https://community.a10networks.com/u/system)\
**Post date:** [April 29, 2016, 2:42pm UTC](https://community.a10networks.com/t/redirect-when-http-response-http-status-contains-200/387/2 "2016-04-29T14:42:11Z")

</div>

Hi Leandro,

Aflex command HTTP::URI valid events are HTTP\_REQUEST and HTTP\_REQUEST\_DATA, that’s why you are getting that error.

What about something like this?

```auto
when HTTP\_REQUEST \{
   set uri [HTTP::uri]
\}

when HTTP\_RESPONSE \{
   if \{ [HTTP::status] contains "200" \} \{

```

HTTP::redirect “[https://myurl.com$uri](https://myurl.com$uri)”

```auto
      \}
\}

```

Kind regards,  
Daniel.
