Jump to content
Welcome to our new Citrix community!

Delete a portion of a path - Rewite?


Recommended Posts

A rewrite policy bound to the request side would seem to be what you are looking for. Either bind it to the LBVS or the CSVS, as appropriate.

 

The policy will look for "url starts with /aaa/", and the action will be a delete, to delete the "/aaa" at the beginning.

Link to comment
Share on other sites

"bassed on /aaa being path index 1. (This part I've figured out.)"

 

Does the above refers to the use of a Pattern Set with /aaa as the first index?  If this is the case you can try the expression below in your rewrite action (of type delete) to choose the target text to be deleted.

 

HTTP.REQ.URL.STARTSWITH_INDEX("PatternSetName").EQ(1)

 

The above assumes you have already created a pattern set named "PatternSetName" and 'aaa' as the string value of index 1.  You can use the same expression above in your rewrite policy bound to your lbvs or csvs.

Link to comment
Share on other sites

Thank you Christopher.

 

I have a CS policy

HTTP.REQ.URL.STARTSWITH("/aaa")

(but

HTTP.REQ.URL.PATH.GET(1).EQ("aaa")

works just as well)

which sends the user to the correct server, but I need to get rid of "/aaa"

 

So as you suggest...

 

I created a pattern set (PAT_DEL_aaa) with "aaa" being index 1

Then I tried creating a Rewrite Action:

Name: ACT_DEL_aaa

Type: Delete

Expression: HTTP.REQ.URL.STARTSWITH_INDEX("PAT_DEL_aaa").EQ(1)

 

It evaluates fine, but I can not create it.  I get an "Invalid argument" exception. There is nothing else on the page that I can modify except the check box "Bypass Safety Check", but that does not help either.

Link to comment
Share on other sites

Hi David ,

 

For your request what do you want to accomplish ? do you want the request going to backend server to be re-written to /SomePath/SomeOtherPath/

 after removing /aaa ?  or do you want the response from the backend server to be rewritten before sending it to the client ?

 

Here is the packet flow diagram of Netscaler illustrating which process(re-write, responder..etc) will get applied when the packet enter the netscaler from Client end and leave toward backend server , also the return path . Based on this you can identify which method should be good for you . http://support.citrix.com/servlet/KbServlet/download/32455-102-691592/CTX135254%20-%20Netscaler%20-%2010.0%20Packet%20Flow.pdf

Link to comment
Share on other sites

Thanks Sanjith.  Now I see that I cannot use a responder...

 

My goal is this:

 

I have an (1) external IP.  Clients connect with https:// fqdn/aaa/SomePath/SomeOtherPath/... or /bbb/..., or /ccc/..., or etc.

Based on index 1 of the path, Content Switching sends the client to one of n internal servers, each listening on a different port.  This works.

 

Where I am having difficulty is that I need to remove path index 1 because the destination server knows no such path. The rest of the path must remain unchanged. 

 

It might also be possible (but I don't know yet as the first part is not working) that the reply must contain /aaa/, /bbb/, etc.

Link to comment
Share on other sites

Based on the packet flow the Client's request will be reaching CS Vserver , which will send to one of the LB Vserver(based on your policy to check /aaa) , so If you apply a rewrite on this LB Vserver ( who will LB the request to the backend server) then the backend server will not see /aaa  in the URL path .

 

The action you tried previously will give invalid argument because you should be selecting the target which can only be a URL, header etc. .. you cant go beyond that is what i found .

 

I tried one action which might work for you :

add rewrite action t replace HTTP.REQ.URL "\"/\"+HTTP.REQ.URL.PATH_AND_QUERY.STRIP_START_CHARS(\"/aaa/\")" -bypassSafetyCheck YES

 

This will strip the /aaa/   and will keep the rest of the URL intact , I have to add / in the begining to compensate for the / i am striping .

This will remove /aaa completly  even if you have a URL starting with /aaas/anything  it will remove the aaa and the result will be /s/anything .

 

Will post the evalutation for reference .

  • Like 1
Link to comment
Share on other sites

In this case you will have to create a new rewrite policy to modify the server's response , by adding /aaa in the start URl .

But to make such policy you should identify the factor on which Netscaler will take this decision i.e how the netscaler will identify whether this response should be rewritten with /aaa or with /bbb .

Link to comment
Share on other sites

  • 3 months later...

I am also trying to achieve the same and based on my tests and the documentation, HTTP.REQ.URL.PATH_AND_QUERY.STRIP_START_CHARS(\"/aaa/\")" will strip any "/" and "a" characters.

 

So, http://<csvserver_name>/aaa/account.html will be rewritten to http://<csvserver_name>/ccount.html (without a on account.html)

 

 

http://support.citrix.com/proddocs/topic/ns-main-appexpert-10-map/ns-pi-basic-operations-con.html

"Strips matching characters from the beginning of the input string until the first non-matching character is found and returns the remainder of the string. You must specify the characters that you want to strip as a single string within quotation marks."

 

Still looking for a solution...

Link to comment
Share on other sites

  • 1 year later...
  • 5 months later...

I am working on the same issue when I apply   the above solution  in 10.1 I get a syntax error 

 

I have xcompany.com/TEST/Path_I_needto go

If I add the following expression it evaluates to 

 

HTTP.REQ.URL.PATH_AND_QUERY.STRIP_START_CHARS("/TEST") 

 

Path_I_needto go

 

and not /Path_I_needto go

 

I have in 

Expression to choose target text reference 

 

HTTP.REQ.URL

 

String expression for replacement text 

HTTP.REQ.URL.PATH_AND_QUERY.STRIP_START_CHARS("/TEST")

 

I tried  to keep the "/"  but it gives a syntax error 

HTTP.REQ.URL "\"/\"+HTTP.REQ.URL.PATH_AND_QUERY.STRIP_START_CHARS(\"/TEST/\")"

Link to comment
Share on other sites

I am working on the same issue when I apply   the above solution  in 10.1 I get a syntax error 

 

I have xcompany.com/TEST/Path_I_needto go

If I add the following expression it evaluates to 

 

HTTP.REQ.URL.PATH_AND_QUERY.STRIP_START_CHARS("/TEST") 

 

Path_I_needto go

 

and not /Path_I_needto go

 

I have in 

Expression to choose target text reference 

 

HTTP.REQ.URL

 

String expression for replacement text 

HTTP.REQ.URL.PATH_AND_QUERY.STRIP_START_CHARS("/TEST")

 

I tried  to keep the "/"  but it gives a syntax error 

HTTP.REQ.URL "\"/\"+HTTP.REQ.URL.PATH_AND_QUERY.STRIP_START_CHARS(\"/TEST/\")"

 

 

 

 

Figure it out in "String expression for replacement text " I have 

 

 

HTTP.REQ.URL.BEFORE_STR("TEST").APPEND("") + HTTP.REQ.URL.PATH_AND_QUERY.STRIP_START_CHARS("/TEST")

 

  • Like 1
Link to comment
Share on other sites

  • 4 years later...
  • 1 year later...
On 9/17/2020 at 5:08 PM, Fabio Ambrosanio said:

instead of using STRIP_START_CHARS which risks deleting other pieces from the string I think it is better to use AFTER_STR

 

add rewrite action act-remove-aaa replace HTTP.REQ.URL "\"/\"+HTTP.REQ.URL.PATH_AND_QUERY.AFTER_STR(\"/aaa/\")"

 

Thank you Fabio, this was really helpful in one of my cases. I used the STRIP_START_CHARS and I noticed it actually removes all the characters uniquely.

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