Forum Discussion

fred_zeig77's avatar
fred_zeig77
Icon for Altostratus rankAltostratus
Jul 22, 2024

Advice to partial rename uri path

Hi there masters!

 

I would like to ask for advice. Is there a possibility that after I redirect an URL I can partial rename the 1st two paths in the redirected URI path?

So, for example: when client requested our main page... "https://companyA.com/" I will redirect this to a path of "https://companyA.com/room/desktop/r/Home"..

 

Then, I will hide/or rename the 1st two paths and this will appear on client's browser as "https://companyA.com/bed/table/r/Home". /bed/table uri path are strings not location or directory. Would this be plausible? I really just want to change their strings.

 

I tried to code it but only the redirect is successful except for the changing of the names of the two paths:

 

When HTTP_REQUEST{

    if {([HTTP::host] equals "companyA.com" and [HTTP::uri]equals "/")}{

         HTTP::redirect "https://[HTTP::host]/room/desktop/r/Home"

  }

}

 

When HTTP_RESPONSE {

    if {[HTTP::header exists "Location"]}{

        HTTP::header replace "Location" [string map {"/bed/table" "/room/desktop"} [HTTP::header "Location"]]

 }

 

}

 

Can you help me on this? Thanks!

 

Regards,

 

Zeig

 

 

  • That's some very specific stuff you're trying to achieve .. 

    If the "client URL" you want to display does not exist on the server, I think you'll need two instructions in the iRule, one to redirect client to target URI and one to change this string before it connects to the webserver. 

    You might try something similar to this

    when HTTP_REQUEST {
      if { [HTTP::host] equals "companyA.com" }{ 
        #I'm using a switch statement so it's easier to add/change uri behavior in the future
        switch -glob [HTTP::path] {
          "/" { HTTP::redirect "https://[HTTP::host]/bed/table/r/Home" }
          "/bed/table/r/Home" { HTTP::path "/room/desktop/r/Home" } 
        }
      }
    }

     

  • That's some very specific stuff you're trying to achieve .. 

    If the "client URL" you want to display does not exist on the server, I think you'll need two instructions in the iRule, one to redirect client to target URI and one to change this string before it connects to the webserver. 

    You might try something similar to this

    when HTTP_REQUEST {
      if { [HTTP::host] equals "companyA.com" }{ 
        #I'm using a switch statement so it's easier to add/change uri behavior in the future
        switch -glob [HTTP::path] {
          "/" { HTTP::redirect "https://[HTTP::host]/bed/table/r/Home" }
          "/bed/table/r/Home" { HTTP::path "/room/desktop/r/Home" } 
        }
      }
    }

     

    • fred_zeig77's avatar
      fred_zeig77
      Icon for Altostratus rankAltostratus

      Alrighty! Thank you master! Will try this irule now.... Thanks again! :)

    • fred_zeig77's avatar
      fred_zeig77
      Icon for Altostratus rankAltostratus

      Thanks sir! It works it was masked now. But, I could see some images of ours got broken. Perhaps this was because of how it was coded. We only did use basic html for testing? We have not use this irule on production yet.

       

       

       

       

       

       

       

       

       

       

       

      But, yes it did mask now. Thanks a Lot!!

       

      • CA_Valli's avatar
        CA_Valli
        Icon for MVP rankMVP

        Try using developer tools to understand how that image is called .. my suspicion would be that it referenecs the root folder "/" 

    • fred_zeig77's avatar
      fred_zeig77
      Icon for Altostratus rankAltostratus

      Hi master!

       

      Greetings! again. Is it okay to ask again for confirmation if you are still available? I notice in the code that because the path of our homepage has changed and masked the path on the side of client's browsers. What if our clients press a button containing a link to another path? would that give us an error 404 since the path the browser knows is the "/bed/table/...../"?

       

      So, if lets say they click a login page button with a link at supposed uri path "/room/desktop/r/Home/Login" from "/room/desktop/r/Home" and this was masked to "/bed/table/r/Home"... Will client's browser able to direct to "/room/desktop/r/Home/Login" with the mask uri path or will this give them an error 404 code since the browser will shoot an HTTP get request header of path "/bed/table/r/Home/Login" when clients click the page's login link/button?

       

      Apologies for the too many questions. This is my 1st time programming and use TCL/irule language. :)

       

       

      Respectfully,

       

      Zeig

      • CA_Valli's avatar
        CA_Valli
        Icon for MVP rankMVP

        Hello, sorry for taking this long to respond, I was on hohliday.

        So, the purpose of the iRule is to redirect clients to a "fake path" while still preserving the "real path" in server-side communication.

        I've written it to be an exact match, as the only way to change the path in client broswer is performing an HTTP redirect; I don't expect clients to know that "/bed/table" does NOT exist. 

         

        If there's hyperlinks that point to /room/desktop/r/Home/Login , client browser will use the information in the hyperlink to perform a brand new GET request using the path that's provided -- this means that clients will be able to reach the "real path" on the server-side directly, and browser will display the real url in this case. iRule will NOT intercept them as the intruction is an exact match.

         

        If you require dynamic matching we need to change the switch statements and add some extra code to preserve the rest of the uri