Forum Discussion
irule to append www to each page
Hi,
I have a website that is available as http://www.webpage.com or http://webpage.com. I need to have all pages resolve back to the www version.
so if a visitor was to go to http://webpage.com/about it will redirect to http://www.webpage.com/about. This needs to happen for everypage.
Is this possible with a irule?
Thanks
Tommy
7 Replies
- Hannes_Rapp
Nimbostratus
when HTTP_REQUEST { if { [string tolower [HTTP::host]] eq "webpage.com") }{ HTTP::respond 301 Location "http://www.webpage.com[HTTP::uri]" Connection Close } } Hi,
You can use an irule to detect if www is present and append it if not present :
when HTTP_REQUEST { if { !([HTTP::host] contains "www.") } { HTTP::host "www.[HTTP::host]" } }Something like this:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] eq "webpage.com" }{ HTTP::respond 301 Location "http://www.webpage.com[HTTP::uri]" Connection Close } }- TommyQuality_26
Nimbostratus
Ha, that was quick. Thanks for that. Just one more thing....
I have some sub domains hitting that VS. IE. http://sub.webpage.com will the rule mean that www will be appended to the subdomain?
Thanks
Tom.
- Hannes_Rapp
Nimbostratus
No, because the conditional statement with 'eq' (stands for equals) will only trigger for an exact match
- TommyQuality_26
Nimbostratus
Great, Thanks for all your help.
Tom.
- janholtz
Altostratus
when HTTP_REQUEST { if { ! [HTTP::host] starts_with "www" } { HTTP::redirect http://www.[getfield [HTTP::host] ":" 1][HTTP::uri] } }Nice and all purpose...
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