Forum Discussion
Modificatioin of irule to append www
I have my irule like this
when HTTP_REQUEST { if { [HTTP::path] equals "/" } { HTTP::redirect "/XYZ.Web/Login.aspx" }
}
When user type https://www.abc.com and it works fine
but when user types abc.com it gives error so i wanted to add something like this
when HTTP_REQUEST {
if { ! [HTTP::host] starts_with "www" } {
HTTP::redirect http://www.[getfield [HTTP::host] ":" 1][HTTP::uri]
}
}
Should i do another irule or i can add if statement under same HTTP_REQUEST ?
- youssef1
Cumulonimbus
Hi Nawaz,
You right, you can use HTTP_REQUEST event to process you redirection. This event is used when the system fully parses the complete client HTTP request headers (that is, the method, URI, version, and all headers, not including the HTTP request body)...
In your case you can do it more easly:
when HTTP_REQUEST { set hostname [string tolower [HTTP::host]] set uri [HTTP::uri] if { ! ($hostname starts_with "www.abc.com") } { HTTP::redirect "http://www.abc.com$uri" return } if { [HTTP::path] equals "/" } { HTTP::redirect "/XYZ.Web/Login.aspx" return } }
Regards
- Stanislas_Piro2
Cumulonimbus
Please explain what you want to do...
in description, you talk about https:// and in irule, you redirect to http service
So :
- if the client requests http://abc.com --> you can redirect to http://www.abc.com without error
- if the client requests http://abc.com --> you can redirect to https://www.abc.com without error
- if the client requests https://abc.com --> you can redirect to https://www.abc.com but you can't prevent TLS error if you don't have a certificate for abc.com. TLS certificate if sent by the server before you can redirect...
You can try this code:
when HTTP_REQUEST { set host [HTTP::host] evaluate host starting with "www." if we need to insert it in redirect. set redirectHost [expr {$host starts_with "www" ? [getfield $host ":" 1] : "www.[getfield $host ":" 1]"} ] evaluate if service is http or https / host starts with "www." If one of these condition is false, prepend to the redirect URI https://$redirectHost set redirectURI [expr {![PROFILE::exists clientssl] || !($host starts_with "www.") ? "https://$redirectHost" : ""}] If path equals / change URI to "/XYZ.Web/Login.aspx" append redirectURI [expr {[HTTP::path] equals "/" ? "/XYZ.Web/Login.aspx" : [HTTP::uri]}] if the URI requires to redirect,redirect to $redirectURI, else, forward to pool as configured in virtual server. if {!($redirectURI equals [HTTP::uri])} { HTTP::redirect $redirectURI } }
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