Jump to content
Welcome to our new Citrix community!

URL Transform to external URL but keep orginial

Recommended Posts



I want to do a rewrite like this.

Incomming: www.domain1.com

Rewrite it to www.domain2.com/test

And keeping original url.


I have done a rewrite with a replace but i got a "HTTP/1.1 400 Bad Request"


Policy is HTTP.REQ.HEADER("HOST").CONTAINS("domain1.com")

Action is  HTTP.REQ.HEADER("Host") "www.domain2.com/test"


I have added an a-record for www.domain2.com in NS.






Link to comment
Share on other sites

Here are some threads with similar examples (and a few references for you as well)




So, to change hostnames in the request from public/client-side to actual/server-side while preserving the path/queries and then to change the internal format back into public format into links in the body uses url transform. And this one isn't that bad to do:


So, your issue above is that you are inserting the "/test" part of the path into the HOST header, which is not where that goes.


So this transformation:

Client side:   http/s://www.domain1.com<path/query stuff>

Rewrite it to Server side:  http/s://www.domain2.com/test<path/query stuff>


You'll need to change the domain AND insert an element into the path.  

Rewrite alone isn't going to do this with the host header, but a URL transform can do this pretty straightforwad. And I made it where it will handle http or https...

add transform action ut_act_demo1 ut_prof_demo 100 -state DISABLED
set transform action ut_act_demo1 -priority 100 -reqUrlFrom "http(s)\?://www[.]domain1[.]com(.*)" -reqUrlInto "http$1://www.domain2.com/test$2" -resUrlFrom "http(s)\?://www[.]domain2[.]com/test(.*)" -resUrlInto "http$1://www.domain1.com$2" -state DISABLED

If you decide you want to do this in rewrite instead,

1) you will need 2 different rewrite policies, one to change the host header of the request  and a separate policy to insert "/test" at the start of the path and query.

2) when you bind the rewrite policy you will need to bind with NEXT so more than one rewrite will apply.  

This will not change any URLs embedded in the response with www.domain2.com/test<stuff> back into www.domain1.com<stuff>


But the basics are this:

add rewrite action rw_act_demo1_replhdr_host replace "http.REQ.HEADER(\"host\")" "\"www.domain2.com\""
add rewrite action rw_act_demo2_inspath_test replace http.REQ.URL.PATH_AND_QUERY "\"/test\" + http.REQ.URL.PATH_AND_QUERY"


# expressions make sure we only rewrite if domain1.com present and if /test is not present on the path one....

add rewrite policy rw_pol_demo1_replhdr_host "http.REQ.HEADER(\"host\").SET_TEXT_MODE(ignorecase).EQ(\"www.domain1.com\")" rw_act_demo1_replhdr_host
add rewrite policy rw_pol_demo1_inspath_test "http.REQ.HEADER(\"host\").SET_TEXT_MODE(ignorecase).EQ(\"www.domain1.com\") && !http.REQ.URL.PATH.GET(1).EQ(\"test\")" rw_act_demo2_inspath_test


bind lb vserver lb_vsrv_demo -policyName rw_pol_demo1_replhdr_host -priority 100 -gotoPriorityExpression NEXT -type REQUEST
bind lb vserver lb_vsrv_demo -policyName rw_pol_demo1_inspath_test -priority 110 -gotoPriorityExpression NEXT -type REQUEST




Link to comment
Share on other sites

13 hours ago, Rhonda Rowland1709152125 said:

But the basics are this:



I did a setup with two rewrite rules as the last example. The rewrite get hits but the trafik doesn't go out again, it wants to go through the LB.

I try to make the request to do a rewrite on CS and out again with original url.

Maybe it's not possible to do that?




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...