xxx.azurewebsites.net doesn't redirect to custom domain after setting up

Xu Wang 40 Reputation points
2023-07-28T00:59:53.3166667+00:00

My Azure Wordpress app servcie landlordgurus.azurewebsites.net doesn't redirect to landlordgurus.com even though custom domain was already setup correctly. landlordgurus.azurewebsites.net is built using "Wordpress on app service". My other websites using old App service does redirect to the custom domain. landlordgurus.com domain is bought from GoDaddy, using Name server from Ezoic (for performance). Wordpress Address (URL) and Wordpress Address (URL) in Wordpress settings are both set to https://landlordgurus.com.

Maybe for that reason, some Google search results shows pages from landlordgurus.azurewebsites.net instead of landlordgurus.com, which is the main problem.

Please help!

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

Accepted answer
  1. SnehaAgrawal-MSFT 17,401 Reputation points Microsoft Employee
    2023-07-31T06:58:21.96+00:00

    @Xu Wang Thanks for reply! You may follow the steps mentioned in this blog to update the Nginx configuration file to redirect your users from azurewebsites.net & to your custom domain.

    1. Go to Azure Portal, open a new SSH session. (https://<your-site-name>.scm.azurewebsites.net/webssh/host)
    2. Update Nginx Default.conf - Server Block (Edit- file is under /etc/nginx/conf.d/default.conf)
    3. Update Nginx Default.conf - Location Block
    4. Save Changes
    5. Use command nginx -s reload to restart the Nginx Service & load the new configuration so that your redirects should be working as expected.

    Hope this helps. Let us know.

    2 people found this answer helpful.
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Xu Wang 40 Reputation points
    2023-08-03T00:27:47.84+00:00

    Well, it looks like it doesn't always work. When I tried to access https://landlordgurus.azurewebsites.net in incognito mode, it doesn't redirect to https://landlordgurus.com. And other people have the same problem. Any idea why?

    1 person found this answer helpful.

  2. SnehaAgrawal-MSFT 17,401 Reputation points Microsoft Employee
    2023-08-09T05:47:55.0433333+00:00

    @Xu Wang

    If the changes you made to the /etc/nginx/conf.d/default.conf file were reverted back, it is possible that the file was overwritten by a configuration update or a deployment to your Azure App Service. This can happen if you are using a deployment slot or continuous deployment, and a new deployment is made that overwrites the configuration file.

    To prevent this from happening, you can use a custom configuration file for Nginx that is not overwritten by deployments or updates. Here are the steps to do this:

    1. Create a new file in the /etc/nginx/conf.d/ directory with a name that ends in .conf. For example, you can create a file named myconfig.conf.
    2. Add your custom Nginx configuration to the new file. This can include the redirect rules that you want to apply.
    3. Modify the /etc/nginx/nginx.conf file to include the new configuration file. Add the following line to the http block of the file: include /etc/nginx/conf.d/*.conf;
    4. This will include all .conf files in the /etc/nginx/conf.d/ directory, including your custom configuration file.
    5. Save the changes to the /etc/nginx/nginx.conf file and restart Nginx to apply the changes. By using a custom configuration file for Nginx, you can ensure that your redirect rules are not overwritten by deployments or updates to your Azure App Service.

    Let us know if issue remains.

    1 person found this answer helpful.

  3. Xu Wang 40 Reputation points
    2023-08-10T04:51:15.45+00:00

    Thank you for your reply. It looks like my change is reverted back after a couple days again. I tried to create myconfig.conf. But not sure if the following screenshot is the right way because the original default.conf has a lot of other sections inside "server" while I only included the part I want to change. How does it know if it should use my new config file part? Thanks

    User's image

    1 person found this answer helpful.

  4. Xu Wang 40 Reputation points
    2023-10-21T21:39:21.03+00:00

    I'm using WordPress on App Service using Linux. The solution was to change wp-config.php, even though in WordPress it shows the correct custom domain in WordPress settings. Redirecting from azurewebsites.net to custom domain works. But later on, I don't know what happened, only root folder redirect works. Other pages/posts redirect stopped working. No help from MS support for that.

    But here's a step-by-step guide on how to successfully change the domain for your WordPress web app:
     

    1. Go to your app service and there go to the advanced tools blade and select go in there. 
    2. This will open a site with a link similar to this https ://<yoursite>.scm.azurewebsites.net
    3. Add this to the URL https ://<yoursite>.scm.azurewebsites.net/newui
    4. In here go to the File manager blade 
    5. After this navigate to your plugins folder, which should be .../site/wwwroot/wp-config.php
    6. In here write the following lines:

    define('WP_HOME','http://www.example.com');
    define('WP_SITEURL','http://www.example.com/site');
     
    For more in-depth instructions, you can refer to the comprehensive guide available at the following link:
    How to use Custom Domains with WordPress on App Service - Microsoft Community Hub

    1 person found this answer helpful.