Options

Simple URL Change

danguijundanguijun Member
Posted by danguijun

Good day Folks, I am looking for a way to change all requests that will arrive at Virtual Server 'VIP_Example' to add/ change the whole URL. I believe we could do the trick sing simple aFlex, but i need assistance on this field.

There are two case studies for this change:

For example:

Case Study#1 - add path to the same domain:

www.example.com will be resolved to IP 200.200.200.20 = VIP_Example01 set on AX. I want AX to change the HTTP requests that will came looking for www.example.com to www.example.com/engineer/nonono/blabla before it forwards to each of the real servers bound to VIP_Example01

Case Study#2 - change URL:

www.example2.com will be resolved to IP 200.200.200.30 = VIP_Example02 set on AX. I want AX to change the HTTP requests that will came looking for www.example2.com to www.example.com/engineer/nonono before it forwards to each of the real servers bound to VIP_Example02

Are these Case studies doable through aFlex?

Thanks

Daniel

Comments

  • Options
    JackofallTradesJackofallTrades Member
    edited February 2014
    Posted by JackofallTrades

    There are two ways that you can do this. The first is a simple redirect. The other is rewriting the URI. if you can I recommend the redirect as it is the easiest.

    The simplest way to do this is:
    Code:





    when HTTP_REQUEST { if {[HTTP::uri] matches "/"} { HTTP::redirect "http://www.example.com/engineer/nonono/blabla" } elseif{[HTTP::host] matches {*\\example2.com} } { HTTP::redirect "http://www.example.com/engineer/nonono/blabla" } }




  • Options
    danguijundanguijun Member
    edited February 2014
    Posted by danguijun

    Thanks, just a few additional questions regarding the code:

    Considering i need only to change the host.domain www.mydomain.com to add a path :7001/pclin/user-login/login.jsp?application=pclin , could the code be like this?

    when HTTP_REQUEST {
    if {[HTTP::uri] matches "www.mydomain.com/"} {
    HTTP::redirect "www.mydomain.com:7001/pclin/user-login/l...lication=pclin"
    }
    }

    On top of that, once aFlex changes the first request adding the path above, my understanding is AX will select among 02 servers to direct the request (e.g. 10.199.1.11 or 10.199.1.12).

    After the first request to www.mydomain.com, many new requests will arrive AX once the user starts to navigate the application.
    What happens with new requests arriving the VIP after the first user request? I only need to add the path to the URL when the request matches exactly www.mydomain.com; but i dont want aFlex to add nothing if the request would be www.mydomain.com:anything/after

    Thanks,

    Daniel
  • Options
    JackofallTradesJackofallTrades Member
    edited February 2014
    Posted by JackofallTrades

    When you are writing an aFlex rule for the HTTP_REQUEST event and you want to do something with the URL; think in terms of the HOST/URI/QUERY.

    If you had a URL that was: www.example.com/foo/bar/dog/cat/somefile...234&my_name=hero

    The first condition could be the host: www.example.com. The second is the URI: "/foo/bar/dog/cat/somefile.php" and the third would be the query: ?myapp_id=1234&my_name=hero"

    If you write a condition that matches the host it would look like this.
    Code:





    ### match host and redirect to another port when HTTP_REQUEST { if {[HTTP::host] matches "www.example.com"} { HTTP::redirect "www.example.com:7001" } }





    If you wanted to match a combination of the host and URI it would look like this.
    Code:





    when HTTP_REQUEST { if {[HTTP::host] matches "www.example.com" and [HTTP::uri] matches "/"} { HTTP::redirect "www.example.com:7001/foo/bar/dog/cat/" } }





    In the example above the redirect will only fire if www.example.com/ is matched. This will not fire if www.example.com/foo is the request.

    Another method to simplify writing your aFlex rules is to supplement commands as variables in your action. Example:

    If you wanted to match a query and then keep the URI and query but redirect to https then.
    Code:





    when HTTP_REQUEST { if {[HTTP::query] contains "myapp_id=1234"} { HTTP::redirect "https://[HTTP::host]:7001[HTTP::uri][HTTP::query]" }




  • Options
    nehakakarnehakakar Member

    Here's how you can implement each case study using aFlex:

    Case Study #1 - Add path to the same domain:

    Create an aFlex script to add the desired path to the incoming requests:

    "HTTP.REQ.URL.SET_TEXT_MODE(IGNORECASE);

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

       HTTP.REQ.URL.PATH_SET("/engineer/nonono/blabla");

    }"

    Case Study #2 - Change URL:

    Create an aFlex script to change the URL of incoming requests:

    "HTTP.REQ.URL.SET_TEXT_MODE(IGNORECASE);

    if (HTTP.REQ.HOSTNAME.EQ("www.example2.com")) {

       HTTP.REQ.URL.HOST_SET("www.example.com");

       HTTP.REQ.URL.PATH_SET("/engineer/nonono");

    }

    "

    I hope it helps you.

Sign In or Register to comment.