13

Configure URL Redirect on Azure Front Door

 3 years ago
source link: https://edi.wang/post/2020/7/10/configure-url-redirect-on-azure-front-door
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Configure URL Redirect on Azure Front Door

Friday, July 10, 2020 China Standard Time - 1009 Reads

Azure Front Door is a global entry point service for websites. Including features like DDOS, WAF, website failover. I have introduced it in "A Brief Introduction for Azure Front Door". This article specifically introduces the usage of URL redirection in Azure Front Door.

When to do URL redirection

URL redirection is mainly used to redirect users to a new location of a resource. The most common case is that the URL of the resource has changed, and the old URL in the search engine, other websites, or the user's browser favorites has not been updated. At this time, if any one try to visit the old URL, it will result in 404. Therefore, we can redirect the old URL to the new URL through URL redirection to ensure that the user can continue to visit it.

Take my blog as an example. My early RSS subscription URL was:

https://edi.wang/subscription/rss

But later changed to

https://edi.wang/rss

However, a large number of users' RSS readers did not update their subscription addresses, so a large number of 404 requests were observed on Azure Application Insights. At this time, URL redirection is required.

In addition, when a website is migrated to a new domain name, URL redirection is also required to ensure that resources are continuously accessible. When facing some sudden marketing events, URL redirection can be used to prevent users from accessing certain web pages, which is also the fastest way to respond.

Why do URL redirects on Front Door

For a website, we can do URL redirection and URL rewriting in many ways. For example, ASP.NET Core's built-in URL Rewrite middleware, IIS's URL Rewrite module, or even write your own code implementation. In an enterprise environment, we can also configure URL redirection and URL rewriting on network products such as F5 BIG-IP. But buying F5 is a huge expense, now that you've already bought Azure, you can use the features provided by Azure Front Door, allowing us to redirect or rewrite URLs without modifying the site configuration or source code.

Configure URL redirection rules

Resource location changes under the same domain name

Take the RSS URL redirection of my blog. I need to redirect /subscription/rss to /rss.

Open Front Door Designer and click + above the Routing rules.

img-fc80a33a-9743-42ec-ae86-4d45d6406efe.png

Enter a Name.

You can chooses HTTP or HTTPS or both depending on your needs, and since my blog is only accessible to HTTPS, I'll choose HTTPS only here.

Enter /subscription/rss in PATTERNS TO MATCH, you can also use * to match anything.

img-f03cf23a-9daa-499d-be57-5af588ee78a0.png

Choose Redirect for Route type

Choose Moved (301) for Redirect type

Set Destination path as Replace, and enter /rss as value

img-5a1f4da1-136f-42a4-b828-859db2ee4323.png

Save your changes and wait a few minutes. Now access to https://edi.wang/subscription/rss will automatically jump to https://edi.wang/rss while my website itself doesn't need to make any code change.

img-cd43d3e3-6f97-4c96-9380-5ec9a6c036a5.png
Jump to another domain name

Still take my blog as example, I don't want users to access my site through Azure Front Door's default domain name, but the default domain name can't be deleted, so I can only let the user jump to the primary domain name. For example, https://ediwangfd.azurefd.net/page/about will automatically redirect to https://edi.wang/page/about

To do this, you need to:

Remove domain names that you do not want users to access from other rules, such as ediwangfd.azurefd.net.

Create a new rule and select this domain name in Frontends/domains. Leave /* in PATTERNS TO MATCH

img-45e8fc01-93fd-43bd-b444-c31447ed0328.png

I selected 302 in Redirect type. The difference between 301 and 302 is that 302 indicates that the redirect is temporary, but 301 indicates that the migration of resources is permanent. When a search engine sees 302, it doesn't update the original URL in it's database, but when it sees a 301, the URL record will be updated. 

Select Replace in Destination host and enter the target domain.

img-8ad95eec-0e5a-4d20-a0a3-9dbdcd9b0b04.png

Save the rule and wait a few minutes, access to azurefd.net is now jumped to the primary domain name.

img-877a3968-e176-4857-85ea-79c6281bd3ea.png

Learn more about Azure Front Door: https://docs.microsoft.com/en-us/azure/frontdoor/front-door-overview


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK