Forum Discussion
Trouble with redirect
I'm trying to write a redirect from the root level of a domain(ex domain.com), to www.domain.com. I know the best and easiest way would be to just put a redirect on the web server, but as sane as that is, its not an option for me.
So here is my iRule.
when HTTP_REQUEST{
if { [HTTP::path] equals "http://domain.com"}
{HTTP::redirect "http://www.domain.com"}
}
I'm getting some generic errors from the iRule editor that aren't of much help. Any assistance would much appreciated. Also if it helps I am running 11.3.
3 Replies
- Victor_142239
Nimbostratus
Should it not be [HTTP::host] instead of [HTTP::path]?
- Brad_146558
Nimbostratus
You are right, I've updated the iRule with host and it still seems unhappy about something in the redirect. when HTTP_REQUEST { if { [HTTP::host] equals "http://domain.com" } { HTTP::redirect "http://www.domain.com" } }
- Hannes_Rapp
Nimbostratus
Notice the error with "http://" string in your host equals statement? Protocol is not part of the HTTP host header 🙂
when HTTP_REQUEST { if { [HTTP::host] equals "domain.com" } { HTTP::redirect "http://www.domain.com" } }A more universal solution for the missing www. problem is below (a single iRule can be used repeatedly for multiple applications):
when HTTP_REQUEST { if { not([HTTP::host] starts_with "www.") } { HTTP::respond 302 location "http://www.[HTTP::host][HTTP::uri]" event disable TCP::close } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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