# Edit aFlex redirect rule to play a bit nicer with URL

**URL:** <https://community.a10networks.com/t/edit-aflex-redirect-rule-to-play-a-bit-nicer-with-url/336>\
**Category:** aFleX\
**Tags:** redirect\
**Created:** [October 13, 2015, 6:31pm UTC](https://community.a10networks.com/t/edit-aflex-redirect-rule-to-play-a-bit-nicer-with-url/336 "2015-10-13T18:31:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![armundo\_m](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@armundo\_m](https://community.a10networks.com/u/armundo_m)\
**Post date:** [October 13, 2015, 6:31pm UTC](https://community.a10networks.com/t/edit-aflex-redirect-rule-to-play-a-bit-nicer-with-url/336/1 "2015-10-13T18:31:02Z")

</div>

Hello,

I am hoping there is an aFlex solution for what I’m trying to do - I currently have an aFlex rule that is:

```auto
when HTTP\_REQUEST \{
 if \{ not([HTTP::host] equals "www.mydomain.com")\} \{

```

HTTP::respond 301 “Location” “[http://www.mydomain.com](http://www.mydomain.com)”

```auto
  \}
\}

```

Basically saying that if the user does not type www., a hard redirect will automatically happen and go to [http://www.mydomain.com](http://www.mydomain.com)

This rule must remain the primary rule in my virtual service set, however this rule is conflicting with  
an additional rule I am trying to add.

The additional rule that I am trying to get working is that when a user visits [mydomain.com/abc-xyz](http://mydomain.com/abc-xyz), the  
rule should redirect to [http://wwww.mydomain.com/abc-xyz](http://wwww.mydomain.com/abc-xyz).

I have tried several different aFlex entries, however the rule listed above will automatically redirect to  
[http://www.mydomain.com](http://www.mydomain.com), and does not keep the /abc-xyz.  
I am willing to alter the original rule listed above to accomplish this if that is possible, as long as the original function is  
also retained.

---

<div class="post-metadata">

**Author:** ![dshin](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@dshin](https://community.a10networks.com/u/dshin)\
**Post date:** [October 13, 2015, 9:03pm UTC](https://community.a10networks.com/t/edit-aflex-redirect-rule-to-play-a-bit-nicer-with-url/336/2 "2015-10-13T21:03:01Z")

</div>

So basically, both your rules will involve the client to go to “[http://www.mydomain.com](http://www.mydomain.com)” but your additional rule is that it keeps the uri. Is that correct? Would it be possible to just add [HTTP::uri] to the end of the 301 response?

```auto
when HTTP\_REQUEST \{
  if \{ not([HTTP::host] equals “www.mydomain.com”)\} \{
   HTTP::respond 301 “Location” “http://www.mydomain.com[HTTP::uri]”
 \}
\}

```

Please try it and let me know if that works for you.

Genard

---

<div class="post-metadata">

**Author:** ![armundo\_m](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@armundo\_m](https://community.a10networks.com/u/armundo_m)\
**Post date:** [October 14, 2015, 2:16am UTC](https://community.a10networks.com/t/edit-aflex-redirect-rule-to-play-a-bit-nicer-with-url/336/3 "2015-10-14T02:16:52Z")

</div>

That did indeed work! Such a simple edit! Thanks!
