Forum Discussion
301 iRule redirection generating an extra 301 status code?!?
Hi,
We have this iRule in place for 301 redirection...
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] eq "sitename.com" } then {
HTTP::respond 301 Location "https://www.sitename.com[HTTP::uri]"
} else {
HTTP::respond 301 Location "https://[getfield [HTTP::host] ":" 1][HTTP::uri]"
}
}
The rule works - but the only thing is that when check the website, we're seeing two 301 redirections happening.
301 Moved Permanently
http://www.sitename.com/
301 Moved Permanently
https://www.sitename.com/
200 OK
Ideally we want to get it down to showing as one single 301 redirect.
Does anyone have any ideas on where the additional 301 redirect could be coming from?
6 Replies
- Chris_Grant
Employee
If I had to hazard a guess I'd say that you have two Virtual servers at play here. Based on the iRule posted I would expect https://sitename.com to redirect to https://www.sitename.com, so that I can't explain. I am guessing that you have another virtual server listening for connections to www.sitename.com:80 and redirecting to :443, which accounts for the second. My recommendation would be to add some logging to your iRule and take an httpwatch capture while it's connecting. You can then compare the logs on the bigIP with the httpwatch and see what is actually happening. Hi,
This irule should not works as "then" is not supported in irules
are you resolving sitename.com and www.sitename.com to the same Virtual Server IP address ?
When you say that you get a redirect to http://www.sitename.com/, is it a mistake and we should understand https instead ?
- 1000blocks
Nimbostratus
Hi Yann. Thanks for your help. Answers to your questions below...
Yes - sitename.com and www.sitename.com resolve to the same Virtual Server IP address.
No - it's not a typo! If we check the HTTP redirection actions that are happening in the browser when accessing our site, it is like this below...
Strange eh?!!
Hi,
May I suggest to use the irule below instead :
when HTTP_REQUEST { if { [string tolower [HTTP::host]] eq "sitename.com" } { HTTP::respond 301 Location "https://www.sitename.com[HTTP::uri]" Test TestRedirect Connection Close } }
I think that the irule originally posted may generate a loop on the client side. moreover, you should see TCL errors on ltm log files as then keyword is not supported (AFAIK)
Do you have a backend that is listening on http ? Can you check that this is really the F5 that generate the redirect not the backend ?
In my example, a redirect caused by F5 should generate a specific header named Test to be sent with the redirect response.
- 1000blocks
Nimbostratus
Interested. With your test rule in place Yann, the flow is this...
Can you add logging information to the irule and check in ltm logs (/var/log/ltm in cli or System >> Logs >> Local Traffic in GUI) :
when HTTP_REQUEST { if { [string tolower [HTTP::host]] eq "sitename.com" } { log local0. "vs_name=[virtual], 301 redirect to https://www.sitename.com[HTTP::uri]" HTTP::respond 301 Location "https://www.sitename.com[HTTP::uri]" Test TestRedirect Connection Close } }
Recent Discussions
Related Content
* 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