Azure Static Web App - How to set up custom domain redirects?

dgb@nc 5 Reputation points
2023-11-03T10:21:50.7966667+00:00

I have a SWA that has the following custom domains:

The app contains a page "/custom"

Is it possible to set a redirect on Azure Static Web Apps like below

'custom.somedomain.com' redirects to 'www.somedomain.com/custom'

I have been able to set this up with DNS redirects, but I am getting certificate errors on some browsers, so want to see if it is possible from the SWA itself

Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,174 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 19,151 Reputation points Moderator
    2023-11-13T20:33:23.8466667+00:00

    Hi @dgb@nc can you share the certificate errors you're getting?

    Yes, it is possible to configure redirects for custom domains on Azure Static Web Apps to route traffic from one domain to a specific page on another domain.

    Here is how you can set up a redirect from custom.somedomain.com to www.somedomain.com/custom:

    1. In your static web app configuration, under "Custom domains", add both www.somedomain.com and custom.somedomain.com.
    2. Under "Routes", add a new route with the following settings:
    • Route: custom.somedomain.com/*
    • Redirect: www.somedomain.com/custom
    • Status code: 301

    This should configure a 301 permanent redirect that will send all traffic from custom.somedomain.com to www.somedomain.com/custom. The redirects are handled by the Static Web Apps service itself, so you don't need to rely on DNS redirects. This should avoid any certificate errors that you were seeing before.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.