Forum Discussion

DaveC_53879's avatar
DaveC_53879
Icon for Nimbostratus rankNimbostratus
Jul 26, 2011

Return a 301 instead of 302

I need my redirects to return a 301 instead if a 302. The Web team is unable to track the rdirected requests because they return a 302. How can I change the rule below to return a 301?

 

 

when HTTP_REQUEST { if { [HTTP::host] starts_with "www."} {

 

HTTP::redirect ]

 

} elseif { [HTTP::host] starts_with "mydomain.com"} {

 

HTTP::redirect ]

 

 

There are more possible redirects in the irule which I've omitted, but they all use the same format. Thanks...

13 Replies

  • I don't think hostnames starting with a hyphen are valid. For example, I assumed for "-peoples.com" that you'd want to match anything ending with -peoples, so I had it as "*-peoples.com".

     

     

    If you don't need a wildcard for one entry, you can just remove the asterisk. If you don't need wildcards for any hostname you can remove all of the asterisks and the -glob flag from the switch statement.

     

     

    Aaron
  • My rule is below. I've changed the host names, but it accurately reflects the rule. It is still only returning a blank page. What am I missing? Thanks.

     

     

    when HTTP_REQUEST {

     

    switch -glob [string tolower [HTTP::host]] {

     

    "www." -

     

    "synergycitizens.net" -

     

    "synergycitizens.com" -

     

    "synergycitizens.mobi" -

     

    "synergycitizens.net" -

     

    "citizensforsynergy.org" -

     

    "citizensforsynergy.net" -

     

    "citizensforsynergy.com" -

     

    "synergyscitizen.org" -

     

    "synergyscitizen.com" -

     

    "synergycitizen.net" -

     

    "synergycitizen.com" -

     

    "synergy-citizen.org" -

     

    "synergy-citizen.net" -

     

    "synergy-citizen.com" -

     

    "synergy-citizens.org" -

     

    "synergy-citizens.net" -

     

    "synergy-citizens.com" -

     

    "synergycitizen.org" { HTTP::respond 301 "http://synergycitizens.org[HTTP::uri]" }

     

    }

     

    }
  • I think it would be best if u clarify exactly what you're looking to accomplish here. If you're looking to catch every host that starts with www you will need the 'www.*' in hoolios example..

     

     

    If your web instances wont accept the base domain, ie yourdomain.com without the A record in front of it, it won't work.. maybe spell out, im looking to catch A and 301 redirect to B..

     

     

    You could always test what host headers your web instances will accept by using your host file to test..