Jump to content
Updated Privacy Statement

Regular expression with URL Transformation


Go to solution Solved by Nicola Campaci,

Recommended Posts

Hi folks,

I have the following problem.
I have a Contentswitch vServer with a path to www.testurl.com/api/. 
However, since in the backend the paths following "api" are located directly under root a URL Transformation Responder Policy 
So far, everything has worked without any problems.
Now, however, additional paths have been added for the URL, which are as follows as an example 

"www.testurl.com/dir/dir2/api/dir3" and this should point to another backend. 

To avoid having to create a policy for each URL, I simply wanted to tell the old policy via REGEX to only take effect if "/api" comes directly after the hostname.

With 

HTTP.REQ.URL.PATH_AND_QUERY.REGEX_MATCH(re:^\/api\/$:)

However, this did not work :( 

Then I thought ok it is due to the still existing URL transformation policy and have adjusted the URL Transformation Policy:

 

HTTP.REQ.HOSTNAME.EQ("testurl.com") &&  HTTP.REQ.URL.PATH_AND_QUERY.REGEX_MATCH(re:^\/api\/$:)

But unfortunately that didn't work either 

In summary, the following should work:

When testurl.com/api is entered, it lands on backend 1 
(Backend 1 has the necessity of URL transformation)

if testurl.com/path/path2/api/path3 is entered land on backend 2 


Does anyone here have any tips

Link to comment
Share on other sites

23 hours ago, Nicola Campaci said:

Hi 

if you want an expression that match only "testurl.com/api/" you can use:

HTTP.REQ.URL.PATH.SET_TEXT_MODE(IGNORECASE).STARTSWITH("/api/")

 

 

Hi Nicola,

thanks for your answer :) 

In your example, wouldn't the policy also apply if 

www.testurl.com/path1/path2/api/... would be entered?

Link to comment
Share on other sites

  • Solution

Hi

The policy with expression HTTP.REQ.URL.PATH.SET_TEXT_MODE(IGNORECASE).STARTSWITH("/api/")
works for any url in the following format:

https://any_domain.xxx/api/any_path
 
If you replace STARTSWITH("/api/") with CONTAINS("/api/") in the expression, then it works with url in the format

https://any_domain.xxx/api/any_path
https://any_domain.xxx/path1/.../pathN/api/
https://any_domain.xxx/path1/.../api/any_path

 

  • Like 1
Link to comment
Share on other sites

The follow expression  

HTTP.REQ.URL.PATH.SET_TEXT_MODE(IGNORECASE).STARTSWITH("/api/").NOT && HTTP.REQ.URL.PATH.SET_TEXT_MODE(IGNORECASE).CONTAINS("/api/")

works for any url in the following format:

https://any_domain.xxx/path1/.../pathN/api/
https://any_domain.xxx/path1/.../api/any_path

except the url

https://any_domain.xxx/api/any_path
 

Edited by Nicola Campaci
  • Like 1
Link to comment
Share on other sites

Posted (edited)

Hi,

since I was stuck on 

.REGEX_MATCH

 all the time to solve the issue, I overlooked that I tested with CONTAINS before and not with "STARTWITH" :/ 

of course it worked now! 

Thank you very much :) 

Edited by nlffel439
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...