none
Simple URL redirection with Azure Application Gateway RRS feed

  • Question

  • Hi, I would like to configure a simple redirection within my Application Gateway. In my case, I have several VMs running a Tomcat with several webapps. When I call the public IP of the gateway, I will get to the Tomcat landing page. I would like to redirect it to a webapp of my choice, so to a "<IP>/<weppapp>".

    Wednesday, November 13, 2019 4:01 PM

Answers

  • Hi, 

    Request header will not contain Location header and that is the reason why it is not taking effect. 

    Also, I tried doing it with the URI header with value "/" and it is creating a loop. 

    Can you handle the redirection in the backend VM itself?

    When the request hits the backend with / , redirect to http://IPofAppGW/myapp/ which will work. 

    Let me know your thoughts. 

    Regards, 

    Msrini

    • Marked as answer by PeterOe Monday, December 2, 2019 7:46 AM
    Thursday, November 14, 2019 12:12 PM
    Moderator

All replies

  • Hi, 

    You can group VMs which are running same applications in a Backend pool. So based on number of applications, you can create separate backend pool for each applications. 

    Once that is done, you can create multi-site listener on Application gateway where you will define the hostname of your web Application. Post that based on the host name in your listener, you can route the traffic to respective backend pools. 

    You can refer the below documentation as well.

    Reference: https://docs.microsoft.com/en-us/azure/application-gateway/application-gateway-multi-site-overview

    Regards, 

    Msrini

    Wednesday, November 13, 2019 4:23 PM
    Moderator
  • Hi,

    unfortunately, this is not what I'm looking for.

    I have one Tomcat running two web applications. A frontend application and a backend application. This setup is on multiple nodes, which are already within a backend pool. Nevertheless, this is not the problem.

    If I type in the IP (or the domain) into the browser, it will be HTTP port 80 by default. Within application gateway, I forward Port 80 to Port 8080, which is the Tomcat in the backend pool. But I need to add the webapp name (of the WAR-file in my tomcat) to the URL.

    For example "MyWebApp" is running on my VMs. If I type in the IP to the browser, I will get to the Tomcat landing page. But I would like to be redirected to "52.146.61.166/MyWebApp".

    Currently, I have a local deployment and within an enginx it's just 2 lines of configuration, because the base path "/" is redirected to "/MyWebApp".

    Unfortunately, within Application Gateway "/" is not a valid path. I already tried "/*", which seems to be a loop, of course and also "/." and "/n", which both also do not have any impact on the behaviour.

    Is there any other chance to just add "/MyWebApp" to the base URL?

    Thursday, November 14, 2019 7:57 AM
  • Hi, 

    You can configure Application Gateway with the URL re-direct by sending "/MyWebApp" in the Location header. By doing that you can when you request AppGW IP, you will be redirected to AppGWIP/myWebApp. 

    Reference: https://docs.microsoft.com/en-us/azure/application-gateway/rewrite-http-headers

    Let me know if that helps. 

    Regards, 

    Msrini

    Thursday, November 14, 2019 8:22 AM
    Moderator
  • Hi, 

    You can configure Application Gateway with the URL re-direct by sending "/MyWebApp" in the Location header. By doing that you can when you request AppGW IP, you will be redirected to AppGWIP/myWebApp. 

    Reference: https://docs.microsoft.com/en-us/azure/application-gateway/rewrite-http-headers

    Let me know if that helps. 

    Regards, 

    Msrini


    Until now, I had the following configuration:

    1. Backend pool = 2 Targets = VMs
    2. Basic Listener on HTTP 80
    3. HTTP settings: Set Session Cookie + Port 8080 (=Tomcat)
    4. Basic Rule with the configured Listener + Backend pool + HTTP settings

    Result: I type in my IP in the address line and land on the Tomcat default page.

    Now I added a rewrite set for my basic rule:

    [Do] Set response header 'Location' == http://<MyIP>/MyWebApp

    Result: I type in my IP in the address line and land on the Tomcat default page. Nothing has changed so far.

    What is wrong here? I tried different location values, but did not get it working yet.

    Thursday, November 14, 2019 9:51 AM
  • Hi, 

    When you try to access the AppGW IP, try to enable debug window in your browser and check if you are able to see a 301 from AppGW with the location header pointing to /mywebApp. 

    You have mentioned the Do part, what about the matching condition, when will this redirection happens?

    Regards, 

    msrini

    Thursday, November 14, 2019 10:03 AM
    Moderator
  • Hi, 

    When you try to access the AppGW IP, try to enable debug window in your browser and check if you are able to see a 301 from AppGW with the location header pointing to /mywebApp. 

    You have mentioned the Do part, what about the matching condition, when will this redirection happens?

    Regards, 

    msrini

    My rewrite rule is:

    [If] request header Location == "http://<MyIP>/"

    [Do] Set response header 'Location' == http://<MyIP>/MyWebApp


    Debug Console:

    I cannot see anything inside the header. The request IP is the gateway IP and all requests are status 200.

    Here are two screenshots:


    Thursday, November 14, 2019 11:21 AM
  • Hi, 

    Request header will not contain Location header and that is the reason why it is not taking effect. 

    Also, I tried doing it with the URI header with value "/" and it is creating a loop. 

    Can you handle the redirection in the backend VM itself?

    When the request hits the backend with / , redirect to http://IPofAppGW/myapp/ which will work. 

    Let me know your thoughts. 

    Regards, 

    Msrini

    • Marked as answer by PeterOe Monday, December 2, 2019 7:46 AM
    Thursday, November 14, 2019 12:12 PM
    Moderator
  • Hi, 

    Request header will not contain Location header and that is the reason why it is not taking effect. 

    Also, I tried doing it with the URI header with value "/" and it is creating a loop. 

    Can you handle the redirection in the backend VM itself?

    When the request hits the backend with / , redirect to http://IPofAppGW/myapp/ which will work. 

    Let me know your thoughts. 

    Regards, 

    Msrini

    I did some further tests, without any result. Seems, that I really need to do it in the backend, which is not very elegant in my eyes.

    It's very sad, that such a powerful tool cannot do a simple redirect from the base path. :-(

    Friday, November 15, 2019 9:47 AM
  • Hi, 

    Just checking in if you have had a chance to see the previous response. If this answers your query, do click “Mark as Answer” and "Up-Vote" for the same which will help the community.

    Regards, 
    Subhash
    Tuesday, November 26, 2019 1:24 PM
    Moderator
  • Hi, I marked your message as the answer. This works, but if the Gateway could do it, it would be much more easy. ;-)

    Monday, December 2, 2019 7:46 AM