'DNS redirect for web app in Azure app service

In Azure app service, I have an URL https://www.mywebsite.com

But I wanted once any user browse for this url (https://www.mywebsite.com) they should redirect to https://yourwebsite.com.

The mywebsite.com is simple HTML content:

<script type=“text/JavaScript” window.onload=function (){

  Try{ var a=windows.location.hostname; if(a.includes(“.azurewebsite.net”))
…………………..
………………….
   }

How can I redirect the url?

As it’s a static page and does not have web.config. Can adding a web.config with redirect rule work?



Solution 1:[1]

Use window.location.replace , it works for me.

if(origin.includes(".azurewebsites")){
    window.location.replace("http://www.google.com");
}

Test Result.

enter image description here

enter image description here

    <!DOCTYPE html>
    <html>
    <head>
    <title>JSSample</title>
    <script 
        src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> 
    </script>
    <script type="text/javascript">
        $(document).ready(function(){
            var origin   = window.location.origin;
            console.log(origin);
            if(origin.includes(".azurewebsites")){
                window.location.replace("http://www.google.com");
            }
        })
      </script>
    </head>

    <body>
    </body>
    </html>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jason