Forum Discussion
DaveC_53879
Jul 26, 2011Nimbostratus
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...
- The_BhattmanNimbostratusHi Dave,
when HTTP_REQUEST{ switch -glob [string tolower [HTTP::host]] { "www.*" { HTTP::respond 301 "http://mydomain.org[HTTP::uri]" } "mydomain.com*" { HTTP::respond 301 "http://mydomain2.org[HTTP::uri]" } } }
- DaveC_53879NimbostratusThanks Bhattman. When I try to add your text just as you have it I get the message below. Am I missing some syntax?
- Ryan_Paras_7933NimbostratusBTW...
- DaveC_53879NimbostratusOK. I figured out the syntax; a missing space. But my rule doesn't work. It just returns a blank page. Sanitized rule below, so there may be some duplicates.
- DaveC_53879NimbostratusRyan,
- Ryan_Paras_7933NimbostratusI am sorry - I think I misunderstood. I thought the issue was your web servers were sending 302's and you wanted to change them to 301's. Please disregard my comments.
- DaveC_53879NimbostratusNP. I appreciate the response.
- nitassEmployee
- hooleylistCirrostratusHTTP::respond will not automatically set the URL in the Location header like HTTP::redirect will. So you need to set the URL as the Location header value. Also, with switch you can use - as an action if it's the same action for multiple cases. Lastly, can you double check your * wildcards to make sure you're using it to match in the correct location. The HTTP::host value will only return www.example.com if the URL is http://www.example.com/some/path.html.
when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { "www.*" - "peoples.net" - "peoples.com" - "peoples.mobi" - "peoplesfor.org" - "peoplesfor.net" - "peoplesfor.com" - "speople.net*" - "speople.org" - "speople.com" - "people.net" - "people.com" - "*-people.org" - "*-people.net" - "*-people.com" - "*-peoples.org" - "*-peoples.net" - "*-peoples.com" - "people.org" { HTTP::respond 301 Location "http://peoples.org[HTTP::uri]" } } }
- DaveC_53879NimbostratusThanks Aaron. Do I need the wildcards at all since I'm matching the host name exactly?
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects