Edit aFlex redirect rule to play a bit nicer with URL

Hello,

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

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

HTTP::respond 301 “Location” “http://www.mydomain.com

  \}
\}

Basically saying that if the user does not type www., a hard redirect will automatically happen and go to 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, the
rule should redirect to 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, 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.

So basically, both your rules will involve the client to go to “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?

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

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