https Redirect with and without folder

Hello experts :slight_smile:

I’m really new to BIG-IP and need to make some irules for some hosts. My Problem is that i need some “special” redirects and the one i searched and tested did not work for me.

What do i need:

If a User goes to https://example.com it should be redirect to https://example.com/content

If a User goes to https://example.com/pwreset it should be redirect to https://example2.com/xxx

If a user goes to https://example.com/admin it should be redirect to Example Domain

when HTTP_REQUEST {

if { [HTTP::path] eq “/” } {

HTTP::redirect “https://example.com/content”

}

if { [HTTP::path] eq “/admin” } {

HTTP::redirect " https://example.com/#/login"

}

elseif { [HTTP::uri] eq “/pwreset”} { HTTP::redirect “https://example2.com/xxx”

}

}

But it looks like that if i go to /admin bigIP redirects to Example Domain but because of the /#/ the first line maches as well. Sorry if it is a dump question but im not really good at writing code and so.

Later i have to check also if teh request for /admin is coming from aninternal or external IP, but thats something i will try after the redirect itself are working.

Would be really great if someone could point me in the right direction or help me out :slight_smile:

best regards

Bela

Try below

when HTTP_REQUEST {
	    switch -glob [string tolower [HTTP::uri]] {
	    	"/" {
			HTTP::respond 301 Location "https://example.com/content"
	        }
	    	"/admin*" {
			if { [class match [IP::client_addr] equals "datagroup_internal"] } {
			HTTP::respond 301 Location "https://example.com/#/login"
	    	} else {
             reject
              }
	        }
	    	"/pwreset*" {
			HTTP::respond 301 Location "https://example2.com/xxx"
	        } default {
            return
	      }
         }
  }

Strange maybe the f5 thinks that /# is a query and not part of the path atribute and this is why Example Domain matches the first rule as the F5 irule path option thinks that Example Domain is https://example.com/.

Try using F5 URI HTTP::uri and maybe do somethink like:

when HTTP_REQUEST {

if { [HTTP::path] eq “/” && not ([HTTP::uri] contains “#/login”) } {

HTTP::redirect “https://example.com/content”

}

The not ([HTTP::path] contains “#/login”) will exclude this URI from matching the first if statement. In other words the two conditions should be matched for the first if statement.

Read:

For basic irule knowedge you may check and I think you got the basic idea from what you have done so far:

https://devcentral.f5.com/s/articles/irules-101-01-introduction-to-irules

Nice example.

Thanks for your imput will give it a try and let you know. Thanks

best regards

Bela

It appears, browser is dropping anything coming after # in the URL. So “Example Domain” is ultimately being recieved at the BIGIP end as “https://example.com/” and you are right it would be redirected to “https://example.com/content” as it will match the 1st condition.

You would have to ask DEV team to change the URL for login or see if adding extra trailing slash (ie. Example Domain) would work or not.