# Redirect to other url

**URL:** <https://community.a10networks.com/t/redirect-to-other-url/529>\
**Category:** ADC - Application Delivery\
**Tags:** redirect, aflex, http, github\
**Created:** [September 12, 2018, 5:45pm UTC](https://community.a10networks.com/t/redirect-to-other-url/529 "2018-09-12T17:45:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![gundam](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@gundam](https://community.a10networks.com/u/gundam)\
**Post date:** [September 12, 2018, 5:45pm UTC](https://community.a10networks.com/t/redirect-to-other-url/529/1 "2018-09-12T17:45:10Z")

</div>

Can we redirect to external url when all real servers failed health check.

---

<div class="post-metadata">

**Author:** ![diederik](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diederik](https://community.a10networks.com/u/diederik)\
**Post date:** [September 12, 2018, 6:46pm UTC](https://community.a10networks.com/t/redirect-to-other-url/529/2 "2018-09-12T18:46:34Z")

</div>

Yes this is possible using aFlex. You can use something like this:

```auto
when HTTP_REQUEST {
   if {[LB::status pool Server_HTTP] == "down" } {
      HTTP::respond 302 Location "https://[HTTP::host][HTTP::uri]"
   }
}

```

Use the HTTP response code that suits your requirements best. Google & Github are your friend 😉 [https://github.com/a10networks/aflex-collection](https://github.com/a10networks/aflex-collection) [https://www.a10networks.com/resources/articles/aflex-examples](https://www.a10networks.com/resources/articles/aflex-examples)

---

<div class="post-metadata">

**Author:** ![gundam](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@gundam](https://community.a10networks.com/u/gundam)\
**Post date:** [September 14, 2018, 5:41pm UTC](https://community.a10networks.com/t/redirect-to-other-url/529/3 "2018-09-14T17:41:01Z")

</div>

Hi diederik

Thank you for the info and so I can put like this?

```auto
when HTTP\_REQUEST \{
   if \{[LB::status pool Server\_HTTP] == "down" \} \{

```

HTTP::respond 302 Location “[https://backup.example.com](https://backup.example.com)”

```auto
   \}
\}

```

Thank you

---

<div class="post-metadata">

**Author:** ![diederik](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diederik](https://community.a10networks.com/u/diederik)\
**Post date:** [September 18, 2018, 11:22am UTC](https://community.a10networks.com/t/redirect-to-other-url/529/4 "2018-09-18T11:22:16Z")

</div>

Yes that should work. Make sufre the `" "` are the correct ones though.  
See the difference in your post and mine.

---

<div class="post-metadata">

**Author:** ![gundam](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@gundam](https://community.a10networks.com/u/gundam)\
**Post date:** [September 19, 2018, 12:45pm UTC](https://community.a10networks.com/t/redirect-to-other-url/529/5 "2018-09-19T12:45:34Z")

</div>

Thank you diederik

How about this case, can I setup redirect for each web site?

1 VIP 205.222.120.38 2 real servers [web001.com](http://web001.com) 10.1.1.1 [web002.com](http://web002.com) 10.1.1.2

hosting multiple web sites on same service-group (server-http)

[https://www.abc.com](https://www.abc.com) → redirect to [maintenance.abc.com](http://maintenance.abc.com) [https://www.def.com](https://www.def.com) → redirect to [maintenance.def.com](http://maintenance.def.com) [https://www.ghi.com](https://www.ghi.com) → redirect to [maintenance.ghi.com](http://maintenance.ghi.com)

Is it possible?

Thank you

---

<div class="post-metadata">

**Author:** ![diederik](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diederik](https://community.a10networks.com/u/diederik)\
**Post date:** [September 19, 2018, 1:20pm UTC](https://community.a10networks.com/t/redirect-to-other-url/529/6 "2018-09-19T13:20:19Z")

</div>

Of course, you could do it something like this:

```auto

when HTTP_REQUEST {
   if {[LB::status pool Server_HTTP] == "down" } {
      set HOST [HTTP::host]
      switch [HTTP::host] {
         www.abc.com { HTTP::respond 302 Location "maintenance.abc.com" }
         www.def.com { HTTP::respond 302 Location "maintenance.def.com" }
         www.ghi.com { HTTP::respond 302 Location "maintenance.ghi.com" }
         default { log "Unknown HTTP::host $HOST cannot redirect, rejecting connection."
                     reject }
      }
   }
}

```

Or like this:

```auto

when HTTP_REQUEST {
   if {[LB::status pool Server_HTTP] == "down" } {
      set HOST [HTTP::host]
      set REDIRECTHOST ""
      switch [HTTP::host] {
         www.abc.com { set REDIRECTHOST "maintenance.abc.com" }
         www.def.com { set REDIRECTHOST "maintenance.def.com" }
         www.ghi.com { set REDIRECTHOST "maintenance.ghi.com" }
         default { log "Unknown HTTP::host $HOST cannot redirect, rejecting connection."
                     reject }
      }
      HTTP::respond 302 Location "$REDIRECTHOST"
   }
}

```

Or you could have the A10 generate the maintenance page for you?

```auto

HTTP::respond 503 content "<html><head><title>Apology
Page</title></head><body>We are sorry, but the site you are looking
for is temporarily out of service<br>If you feel you have reached this
page in error, please try again.<p></body></html>"

```

If you always remove the www and put “maintenance” in front of the hostname you could also look at using `regsub` to replace “www.” in the host with “maintenance.”.

---

<div class="post-metadata">

**Author:** ![gundam](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@gundam](https://community.a10networks.com/u/gundam)\
**Post date:** [September 20, 2018, 8:42pm UTC](https://community.a10networks.com/t/redirect-to-other-url/529/7 "2018-09-20T20:42:52Z")

</div>

Thank you diederik

When I applied this aflex,

when HTTP\_REQUEST {  
if

```auto
\{[LB::status pool dlteam-group108\_port443] == “down” \}

\{ HTTP::redirect “http://maintenance.example.com/maintenance.html” \}

\}

```

This error massage showed up

Warning: aFleX syntax error: line 3: “wrong # args: no expression after “if” argument”

dlteam-group108\_port443 is service-group name  
Thank you

---

<div class="post-metadata">

**Author:** ![diederik](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diederik](https://community.a10networks.com/u/diederik)\
**Post date:** [September 21, 2018, 9:08am UTC](https://community.a10networks.com/t/redirect-to-other-url/529/8 "2018-09-21T09:08:15Z")

</div>

That is most likely because you quotation marks are wrong. Note the difference between: `if {[LB::status pool Server_HTTP] == "down" } {` and you version:

```auto
if
{[LB::status pool dlteam-group108_port443] == “down” }

```

You need to use `""` And you are missing a {

---

<div class="post-metadata">

**Author:** ![ericn](https://avatars.discourse-cdn.com/v4/letter/e/f4b2a3/32.png) [@ericn](https://community.a10networks.com/u/ericn)\
**Post date:** [September 21, 2018, 8:25pm UTC](https://community.a10networks.com/t/redirect-to-other-url/529/9 "2018-09-21T20:25:46Z")

</div>

An easier, and generally more efficient way, to do redirect to URL when the service-group is down (usually because all the servers in that group are down) is to use an HTTP template.

```auto
slb template http MY_HTTP
   . . .
   failover-url http://sorry.example.com
   . . .

slb virtual-server VIP <some.ip.addr>
   port 80 http
      . . .
      template http MY_HTTP
      . . .

```

The `. . .` stuff is a stand-in for other needed or desired configuration. In the case of the `template http`, maybe the only feature you want to use is `failover-url`, which is fine. I have seen the `failover-url` used in two basic ways (although I am sure there are more) 1. Lots of vPorts redirect to the same “fail-whale” page somewhere else 2. There are 2 data-centers, perhaps we’re using GSLB, and each location redirects to a specific URL that resolves to another data-center, something like `east.www.example.com` and `west.www.example.com`. Of course, there is a bunch more DNS related config to make such a design work.

---

<div class="post-metadata">

**Author:** ![gundam](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@gundam](https://community.a10networks.com/u/gundam)\
**Post date:** [September 24, 2018, 9:03pm UTC](https://community.a10networks.com/t/redirect-to-other-url/529/10 "2018-09-24T21:03:26Z")

</div>

I put “” and got new error.

```auto

when HTTP_REQUEST {

     if {[LB::status pool “dlteam-group108_port443”] == “down” } {

          HTTP::redirect “http://maintenance.example.com/maintenance.html”

     }

}

```

Warning: aFleX syntax error: line 3: “syntax error in expression “[LB::status pool “dlteam-group108\_port443”]…”” Thank you

---

<div class="post-metadata">

**Author:** ![diederik](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diederik](https://community.a10networks.com/u/diederik)\
**Post date:** [September 25, 2018, 7:17am UTC](https://community.a10networks.com/t/redirect-to-other-url/529/11 "2018-09-25T07:17:53Z")

</div>

I’m afraid you are still using the wrong quotation marks, and you do not need to put quotation marks around the pool name. Do not use word/wordpad or any other word processing tool that wants to intelligently look at your text. You need a plain-text editor or a code-writing tool that does not adjust the quotations to an open and close version. The neutral (vertical) quotation mark is used in coding. Your code needs to look like this:

```auto

when HTTP_REQUEST {
     if {[LB::status pool dlteam-group108_port443] == "down" } {
          HTTP::redirect "http://maintenance.example.com/maintenance.html"
     }
}

```
