Jump to content

URL Rewrite - How to preserve parts of the URL?


Todd Harrington

Recommended Posts

I have a feeling there is probably a very simple answer to this question but I am not 100% how to accomplish this so wanted to ask the community. 

 

I am doing a simple rewrite where I just want to replace the first part of the URL but preserve everything else after the first element. I think I have the rewrite action good to go with the exception of the expression to maintain everything after the first path. 

 

So for example

 

This is the original URL:

 

https://content.company.com/gateway/wdsl?blah

 

This is what I want to accomplish: 

 

https://content.company.com/gatewayadvanced/wdsl?blah

 

 

I only want to modify the first part of the URL and preserve anything else in the path after that. 

 

Anyone out there that can help me out with the regex part of that? Maybe I do not need to do anything and the NS will automatically preserve it the way I have the rewrite written already but I just did not want to have the rewrite replace the first URL element and then strip the rest of the URL out. 

 

My current rewrite policy looks like this so far

 

http.REQ.URL.PATH.GET(1).EQ(gateway)  

 

Then action is: 

 

replace "HTTP.REQ.URL.PATH.GET(1)" "\"gatewayadvanced\""

 

Is there a better way to do this and will this accomplish what I think it should? 

 

Thanks in advance. 

 

 

Link to comment
Share on other sites

10 minutes ago, Todd Harrington said:

I have a feeling there is probably a very simple answer to this question but I am not 100% how to accomplish this so wanted to ask the community. 

 

I am doing a simple rewrite where I just want to replace the first part of the URL but preserve everything else after the first element. I think I have the rewrite action good to go with the exception of the expression to maintain everything after the first path. 

 

So for example

 

This is the original URL:

 

https://content.company.com/gateway/wdsl?blah

 

This is what I want to accomplish: 

 

https://content.company.com/gatewayadvanced/wdsl?blah

 

 

I only want to modify the first part of the URL and preserve anything else in the path after that. 

 

Anyone out there that can help me out with the regex part of that? Maybe I do not need to do anything and the NS will automatically preserve it the way I have the rewrite written already but I just did not want to have the rewrite replace the first URL element and then strip the rest of the URL out. 

 

My current rewrite policy looks like this so far

 

http.REQ.URL.PATH.GET(1).EQ(gateway)  

 

Then action is: 

 

replace "HTTP.REQ.URL.PATH.GET(1)" "\"gatewayadvanced\""

 

Is there a better way to do this and will this accomplish what I think it should? 

 

Thanks in advance. 

 

 

 

Hi 

 

You can try Responder Policy.

 

HTTP.REQ.URL.EQ("/")

 

 Responder Action

 

"/gatewayadvanced/wdsl?blah"

 

Thanks 

Manoj

 

 

 

Link to comment
Share on other sites

Thanks for the response Manoj. The problem with this is that there may be other URLs coming through this VIP that I do not want to replace and just by using a single "/" as the trigger I believe all URL's regardless of what comes through will be replaced with "/gatewayadvanced/wdsl?blah" and I do not think this will function as the application owners want it to. 

 

So for example we may get requests coming in that are like: 

 

/gateway/wdsl?blah1 

 

or

 

/application/directory 

 

or 

 

/blah.html 

 

and I do not want to replace those URL's or it will break application functionality 

Link to comment
Share on other sites

Try this with rewrite

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

 

or Responder policy

From Carl Stalhood

https://discussions.citrix.com/topic/378137-responder-policyredirect-to-url-but-retain-the-entire-path/

 

Leave Portal off of your redirect and add HTTP.REQ.URL.PATH_AND_QUERY.HTTP_URL_SAFE. This reads the original path and query.

Link to comment
Share on other sites

Todd, I think I've got your policies triggering only on "/gateway and not other use cases.  Possibly "/" if needed.  But not if other path elements are included. But double check.  The policy logic will impact which actions you need. AND some variances in what you do want to happen with "/" only vs "/<other stuff>".  

 

A rewrite may not be your best option, unless you don't want the user to see the change in path and only change it on the backend. If this needs to affect outbound links too that get returned to user, then you might even need url transform instead.

 

If you need the user to make a connection to the new path, then a responder redirect will do it as a better alternative.

So, you do need to figure out if Rewrite, URL Transform, or Responder is the feature you need.

 

Rewrite:

With the rewrite .get(1), you do not need to include slashes, as it gets the element between the slashes.  But you would have issues if the original path is "/" only as there is no .get(1) defined.  But there are lots of different ways to do this and you have some examples in the other replies.

 

So in this example, the action will only rewrite if the url starts with /gateway/.  And still preserve all path/query elements:

add rewrite action rw_act_replaceurl replace "http.REQ.URL.PATH.GET(1)" "\"gatewayadvanced\""
add rewrite policy rw_pol_replaceurl "http.REQ.URL.PATH.GET(1).SET_TEXT_MODE(ignorecase).EQ(\"gateway\")" rw_act_replaceurl
 

You would need a separate policy to rewrite / to /gatewayadvanced/ as .get(1) isn't defined if there is no path. Unless you are okay with "/" remaining "/".

add rewrite action rw_act_replaceurl_defaultpath replace http.REQ.URL.PATH "\"/gatewayadvanced/\""
add rewrite policy rw_pol_replaceurl_defaultpath "http.REQ.URL.PATH.EQ(\"/\")" rw_act_replaceurl_defaultpath
 

--------------

Responder/Redirect:

If you want users redirected to /gatewayadvanced, then a responder policy would be needed. And while regex's can be used for this; the regular string operators are usually fine.

Because your original requests could be:

/

or

/gateway

or

/gateway/<path>?<query>

It would be easier, to have two redirect policies 1) for "/" only and 2) a separate policy for "/gateway" that would handle gateway only or gateway + <Path>/<query>.  Its a little trickier to try to make one action do both conditions.

This uses the after_str() operator. You can use other ways to achieve this.

 

If needed you could then have a high priority policy that matches on .eq("/") if you need it to go to "/gatewayadvanced/" only.  This should handle slashes properly.

add responder action rs_act_sendto_gwyadv1 redirect "\"/gatewayadvanced\" + http.REQ.URL.PATH_and_query.AFTER_STR(\"gateway\") -responseStatusCode 301
add responder policy rs_pol_sendto_gwyadv1 "!http.req.URL.PATH.EQ(\"/\") && !http.REQ.URL.PATH.SET_TEXT_MODE(ignorecase).STARTSWITH(\"/gatewayadvanced\")" rs_act_sendto_gwyadv1
 

 

 

  • Like 2
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...