F5 is upgrading its customer support chat feature on My.F5.com. Chat support will be unavailable from 6am-10am PST on 1/20/26. Refer to K000159584 for details.

Forum Discussion

cymru81's avatar
cymru81
Icon for Altocumulus rankAltocumulus
Sep 17, 2021

https non www redirect

Hi, im trying to use an irule to direct traffic from https://example.com to https://www.example.com, im using the following but it just wont work! Any suggestions appreciated!

 

when HTTP_REQUEST {

if {[string tolower [HTTP::host]] equals "example.com"} {

HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" 

}}

3 Replies

  • Hi cymru81,

    This iRule should work. Is there any other irule attached in virtual server?

    After adding the log lines, can you investigate the ltm logs?

    when HTTP_REQUEST {
    	log local0. "wwwredirect1 | Host: [HTTP::host]"
    	if { [HTTP::host] equals "example.com" } {
    		log local0. "wwwredirect2 | Host: [HTTP::host]"
    		HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]"
    		return
    	}
    }
  • Hi, thanks for the reply - no other irules are applied.

    if i enable the logging, where can i pickup the logs from to review please?

  • just checking the ltm log and this (obv replaced) is logged for the VS, if that could be relevant (2.2.2.2 being the VIP)?

     

    SSL Handshake failed for TCP 1.1.1.1:35262 -> 2.2.2.2:443