how to re-direct non-www domain to in Wordpress App Service

Aj 0 Reputation points

I have setup the domain (let's call it as a custom domain for a Wordpress App Service. is pointing to the CNAME record generated by the App Service. and is pointing to the IP address generated by App Service. (this is configured in Google Cloud DNS)

I want and to redirect to

How can I achieve this?

I have tried setting the nginx [dot] conf file in the wwwroot directory and it does nothing. Same with adding a redirect rule in the [dot] htaccess file , and any time I modify the /etc/nginx/conf.d/default.conf file, it just gets overwritten when I restart the app.

Any advice would be greatly appreciated. Thanks.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,041 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 16,771 Reputation points

    Hello @Aj to achieve your redirection for,, and, you can follow these steps:

    1. In the WordPress admin dashboard, go to "Settings" > "General" and ensure that the "WordPress Address (URL)" and "Site Address (URL)" fields are set to "".
    2. If you're using an Application Gateway or Front Door service in Azure, you can set up URL redirection rules there. This is generally the recommended approach as it offloads the redirection logic from the App Service instance.
    • For Application Gateway, follow the instructions in the Azure documentation to create a rewrite rule that redirects HTTP to HTTPS and non-www to www.
    • For Front Door, follow the instructions in the Azure documentation to create a rewrite rule for the desired redirection.
    1. If you don't have an Application Gateway or Front Door, you can configure the redirection within the Web App itself. However, this approach is less recommended as it adds overhead to the App Service instance. a. Create a web.config file in the root directory of your WordPress installation (same level as wp-config.php). b. Add the following code to the web.config file:
         <?xml version="1.0" encoding="UTF-8"?>
                         <rule name="Redirect to HTTPS" stopProcessing="true">
                             <match url="(.*)" />
                                 <add input="{HTTPS}" pattern="^OFF$" />
                             <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
                         <rule name="Redirect to www" stopProcessing="true">
                             <match url="(.*)" />
                                 <add input="{HTTP_HOST}" pattern="^bob\.com$" />
                             <action type="Redirect" url="{R:1}" redirectType="Permanent" />
      This web.config file contains two rules:
      • The first rule redirects HTTP traffic to HTTPS.
      • The second rule redirects non-www traffic ( to www (

    After making these changes, your website should be accessible via, and any requests to or should be redirected to

    Note: If you're using an Application Gateway or Front Door, you can skip step 3 and rely on the redirection rules set up in those services. Hope that helps.


    0 comments No comments