Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

F5 IRULE Replace path with subdomain

Anatolyint
Nimbostratus
Nimbostratus

Hello,

 

 

I need to make an irule to replace HTTP::path with Subdomain, like this:

 

 

 

http://domain.com/PATH/blahblah ===>> http://PATH.domain/blahblah

 

 

The path is dynamic,

 

I was trying to make something like this:

 

when HTTP_REQUEST { 

if { [HTTP::host] contains "domain.com[HTTP::path][HTTP::uri]" } { HTTP::redirect "https://[HTTP::path].domain2.com/edocument[HTTP::uri]" }

}

 

 

 

Is is possible?

Thanks.

 

 

 

 

 

 

 

 

 

5 REPLIES 5

SanjayP
MVP
MVP
when HTTP_REQUEST {
    set path [lindex [split [string tolower [HTTP::uri]] "/"] 1]
    set uri [string map -nocase "/$path/ /" [HTTP::uri] ]
    HTTP::respond 301 Location "https://$path.domain.com$uri"
      }

Anatolyint
Nimbostratus
Nimbostratus

Thanks,

 

How can i apply this only if domain matches DOMAIN.COM for example?

Let us know how the testing goes

when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::host]] {
	  "domain.com"
	   {
	    set path [lindex [split [string tolower [HTTP::uri]] "/"] 1]
        set uri [string map -nocase "/$path/ /" [HTTP::uri] ]
        HTTP::respond 301 Location "https://$path.domain.com$uri"
      }
	   } 
 	   default {
          return
      }
    }
 }

Anatolyint
Nimbostratus
Nimbostratus

Works!

 

Thank you for your help.

SanjayP
MVP
MVP

cool. Please select an option as best to change the status to resolve.