Forum Discussion
iRule to add www without changing URL
Hello F5 community,
Is there a way to add www in front of the URL while keeping the URL intact? For example:
https://abc.com/testfolder/blahblahblah changed to https://WWW.abc.com/testfolder/blahblahblah..
Thanks.
Do you want to change Host header sent from the client in server side connection or do you want to redirect the client to https://WWW.abc.com/testfolder/blahblahblah
to redirect the client, use following code
when HTTP_REQUEST { if {[HTTP::host] eq "abc.com"} { HTTP::redirect "https://www.abc.com[HTTP::uri]" } }
- JGCumulonimbus
Probably a description of the problem you are trying to solve would help here.
- MihirP1129Nimbostratus
I don't know the full details, but what I was told from our web developers, is that this is related to an SSO authentication between the client and us. Client host a site on their end which the user authenticate to, then they click on a link on the page that takes them to a URL we host (let's say we host abc.com). So the minute the user clicks on the link, it'll send a request for https://abc.com/blahblahappenduserID (it'll append a unique ID or info to the URL) but the SSO authentication is failing, because it needs to be https://WWW.abc.com/blahblahappenduserID. I'm trying to figure out a way to add the www for the incoming request without changing the URL. Hope that makes sense.
- Lee_SutcliffeNacreous
Depends what you want.. if you expicitly what to replace "abc.com" with "www.abc.com" you can use this iRule.
when HTTP_REQUEST { if {[HTTP::host] eq "abc.com"} { HTTP::header replace "Host" "www.abc.com" } }
If you want to add "www" to any host that doesn't have "www" then that's a different request, so a bit more context would be helpful.
Lee
- MihirP1129Nimbostratus
Hi Lee, please see my response above of what I'm trying to accomplish.
- Lee_SutcliffeNacreous
Have you tried your code? Reading your description above, it sounds like the iRule you supplied should work. Changing the incoming host header from abc.com to www.abc.com will leave the URi/Path intact
- Stanislas_Piro2Cumulonimbus
Do you want to change Host header sent from the client in server side connection or do you want to redirect the client to https://WWW.abc.com/testfolder/blahblahblah
to redirect the client, use following code
when HTTP_REQUEST { if {[HTTP::host] eq "abc.com"} { HTTP::redirect "https://www.abc.com[HTTP::uri]" } }
- MihirP1129Nimbostratus
I tried this irule and it didn't work, because when I try to hit abc.com/blahblahbalhID, nothing happened.
- Stanislas_Piro2Cumulonimbus
Unlikely! You may have done wrong change to match your real host
- MihirP1129Nimbostratus
To complicate things even more, I found out that the web developer has a redirect hardcoded in the code for http://abc.com or http://www.abc.com to go to https://www.abc.com/web/default.aspx. I added the redirect iRule (Stanislas Piron) mentioned above to the 443 VS on the F5, and when I test a site https://abc.com/web/default.aspx?frm=test-option3, I get a "Hmm.. can't reach this page" in firefox. It shows Protocol (Pending) and Result (Pending) when do a Network debugging in FF when hitting that site. The redirect in the code has to stay for the site to work properly. I'm not sure how to make this work. Maybe conflicts in multiple redirects? looping?
- Stanislas_Piro2Cumulonimbus
you can also do the same with LTM Policy:
rule 1 :
- conditions :
- http-host equals "abc.com"
- http-uri path segment equals /
- actions
- http redirect https://www.abc.com/web/default.aspx
rule 2 :
- conditions :
- http-host equals "abc.com"
- actions
- http redirect tcl:https://www.abc.com[HTTP::uri]
- MihirP1129Nimbostratus
The order in which the irule was placed on the F5 was the issue. After moving the irule to the bottom of the list, it worked! Thanks everyone!
- Lee_SutcliffeNacreous
If you have more than one iRule on a VIP I would seriously recommend using priorities on your events. This way you can control the ordering of your events rather than relating on list ordering which is not ideal.
https://devcentral.f5.com/s/articles/the101-irules-101-events-amp-priorities
when HTTP_REQUEST priority 100 { #this event will fire SECOND } when HTTP_REQUEST priority 10 { #this event will fire FIRST }
- conditions :
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