For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

kalav's avatar
kalav
Icon for Nimbostratus rankNimbostratus
Jan 26, 2021
Solved

Redirect in iRule based on host and URI

I have a virtual server on port 80 redirecting traffic to another vs on 443 via http 301 responses in an iRule: if { [HTTP::host] equals "www.myexample.com" or [HTTP::host] equals "myexample.com"...
  • Enes_Afsin_Al's avatar
    Jan 26, 2021

    Hi Kev,

     

    The elseif on lines 4-5, must be after the line 23 in your code.

    4. elseif { [HTTP::host] equals "blog.myexample.com"} {

    switch version:

    when HTTP_REQUEST {
    	switch [HTTP::host] {
    		"www.myexample.com" -
    		"myexample.com" { HTTP::respond 301 Location "https://myexample.com[HTTP::uri]"	}
    		"blog.myexample.com" {
    			switch [HTTP::uri] {
    				"/ddc" -
    				"/tree-tales" -
    				"/made-here" -
    				"/con21-reaction" { HTTP::respond 301 Location "https://uk.myexample.com" }
    				"/btp" { HTTP::respond 301 Location "https://uk.myexample.com/projects/uk/b-2-p/" }
    				"/bas" { HTTP::respond 301 Location "https://uk.myexample.com/projects/uk/b-a-s" }
    				"/tenbelt" { HTTP::respond 301 Location "https://myexample.com/belt" }
    				"/urban" { HTTP::respond 301 Location "https://myexample.com/U_L_C" }
    				"/bhfl" { HTTP::respond 301 Location "https://uk.myexample.com/projects/uk/b_h_f_l" }
    				default { HTTP::respond 301 Location "https://myexample.com[HTTP::uri]" }
    			}
    		}
    	}
    }