Jump to content

URL Transformation into subdirectory


Recommended Posts

Hello,

 

i want to archive a simple url transformation. The user should only request the url https://server.domain.com  and all requests should be transformed into the subdirectory app

 

So that the user dont see the subdirectory in the url. (https://server.domain.com/app)

 

Can someone help me, how i can create those simple transform rule ?

Thanks

Link to comment
Share on other sites

If you just need to insert the directory in the user requests as it passes to the server, but you don't need to modify links in the response, you might be able to use a simple rewrite instead.

 

Option 1: Rewrite policy

This would just insert the path "app/" in front, if not already present and if the path wasn't exactly "/".  Note, this will hide the change from users, but won't modify any paths returned from the web server in the response as links to the user.

add rewrite action rw_act_inspath_app insert_before "http.REQ.URL.PATH.GET(1)" "\"app/\""
add rewrite policy rw_pol_inspath_app "!http.REQ.URL.PATH.EQ(\"/\") && !http.REQ.URL.PATH.GET(1).SET_TEXT_MODE(ignorecase).EQ(\"app\")" rw_act_inspath_app

 

And a response time policy could remove this; this would be the easier method than URL transformations, if the scenario isn't that complex.  Also, I'm not accounting for any relative paths at this time. 

 

Option 2: URL Transform

If you want to transform all requests to "/app", and then remove that directory in any links in the response on the client side, then url transform should work. But is this a single static string "/app" or are you transforming different requests to different values /appa, /appb, /appc...for that, the example I'll give you wouldn't handle it.

The reality is that even what we think is a "simple" url transform scenario might be more complicated than you anticipate, so your requirements might change or you might need more rules/policies to get the job done.

 

If you are sure that all requests will be rewritten from /<stuff> to /app/<stuff>, then something like this should work:

REQ URL FROM: http(s?)://server[.]domain[.]com(.*)

REQ URL TO:  http$1://server[.]domain[.]com/app$2

RES URL From:  http(s?)://server[.]domain[.]com/app(.*)

RES URL TO:  http$1://server[.]domain[.]com$2

 

The actual transform action and policy would be like this:

add transform profile urlt_demo_appdir
add transform action urlt_insapp_intopath_absolute urlt_demo_appdir 200
set transform action urlt_insapp_intopath_absolute -priority 200 -reqUrlFrom "http(s?)://server[.]domain[.]com(.*)" -reqUrlInto "http$1://server[.]domain[.]com/app$2" -resUrlFrom "http(s?)://server[.]domain[.]com/app(.*)" -resUrlInto "http$1://server[.]domain[.]com$2"
 

# policy expression, avoids performing the transform if the "/app" path already exists.

# You might need to decide what to do if a request is exactly:  https://server.domain.com/ and what to do in this case. So the expression might need to exclude an additional scenario.

add transform policy urlt_pol_demo_appdir "!http.REQ.URL.PATH.SET_TEXT_MODE(ignorecase).STARTSWITH(\"/app\")" urlt_demo_appdir
 

I didn't fully test this one; but it should be in the ballpark based on the initial request.

 

If relative paths need to be adjusted too, then an additional transform rule will be needed. I can mock it up later.

Note: This may not handle everything you need it to, if your actual requirements are more complex than indicated.

 

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