Forum Discussion
Inserting "www" or redirecting to "www"
Hi,
My client has changed their back end servers from Coldfusion to Liferay. The Tomcat within the new Liferay only accepts "http://www.example.com" so when users try "http://example.com" it fails. So I wrote a basic iRule to redirect the users browser to use "www" in the request. Mostly it works fine, but the URI is lost and I'm really sure if this is the correct way to this.
Any suggestions?
Thanks!
iRule is:
when HTTP_REQUEST { set host [HTTP::host] if { [HTTP::host] equals "example.com" } { HTTP::respond 301 Location "http://www.$host/" } }
4 Replies
- Rustic_57941
Nimbostratus
Was wondering if this would retain the URI: when HTTP_REQUEST { set host [HTTP::host] if { [HTTP::host] equals "example.com" } { HTTP::respond 301 Location "http://www.$host[HTTP::uri]" } }
- Matt_Dierick
Employee
You don't need to set a host variable. You can do something like that :
when HTTP_REQUEST { if {string tolower [HTTP::host] equals "example.com" } { HTTP::respond 301 Location "http://www.[HTTP::host][HTTP::uri]" } }This should work.
- Michael_Yates
Nimbostratus
You will need to enclose the "string tolower" in brackets.
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "example.com" }{ HTTP::respond 301 Location "http://www.[HTTP::host][HTTP::uri]" } } - Rustic_57941
Nimbostratus
Thanks Michael - your version with the brackets works prefect.
Rgds, Mark
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