How to create a 301 redirect for Wordpress site on App Services

Joe O 10 Reputation points
2023-01-24T14:29:32.5333333+00:00

I need to redirect www.example.com to example.com. I recently created a Word Press website using Azure App Services, as described here:

https://learn.microsoft.com/en-us/azure/app-service/quickstart-wordpress

I have created and mapped a custom domain, using free SSL certificate from App Service. DNS is managed by Microsoft 365, Non www and www are functioning and accessible via browser.

My website installation, as referenced above, includes PHP v8 and web server nginx. Based on some research, it is my understanding that nginx does not read htaccess rules.

I also explored Application Gateway, but it appears that my free SSL certificate cannot be exported to Application Gateway to redirect https traffic.

What are my options. How can I create the redirect? I do not have a technical background, so detail that I can follow, or reference to material that I can follow without knowing how to write code would be best. Thanks

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

2 answers

Sort by: Most helpful
  1. Grmacjon-MSFT 19,151 Reputation points Moderator
    2023-02-02T23:05:16.8766667+00:00

    Hi Joe O ,

    Thanks for using Azure. Apologies for the delay in the response.

    You can use a free Azure SSL certificate with Azure Front Door to redirect HTTPS traffic. To do this, you will need to create a Front Door with an existing Web App resource and then add the certificate to the Front Door using the Azure portal. You can then create a routing rule to redirect HTTP traffic to HTTPS.

    To use a free Azure SSL certificate with Azure Front Door for a WordPress site hosted on Azure, you will need to follow these steps in the Azure Portal:

    1. Select Create a resource found on the upper left-hand corner of the Azure portal.
    2. Search for Front Door and CDN profiles using the search bar and once you find the resource type, select Create.
    3. Select Explore other offerings, then select Azure Front Door (classic). Select Continue to begin configuring the profile.
    4. Choose a subscription and then either use an existing resource group or create a new one. Select Next to enter the configuration tab.
    5. The configuration for Front Door happens in three steps - adding a default frontend host, adding backends in a backend pool and then creating routing rules to map the routing behavior for frontend host. Select the '+' icon on the Frontend hosts to create a frontend host.
    6. Enter a globally unique name for your default frontend host for your Front Door. Select Add to continue to the next step.
    7. On the Route Details section, set the Route Type to Forward. Ensure that the right backend pool gets selected and the Forwarding Protocol is set to HTTPS only.
    8. Select Add to save the routing rule for request forwarding.
    9. Select Review + create and then Create, to create your Front Door profile. Go to the resource once created.

    Once you have created the Front Door, you can then add the SSL certificate to it by following these steps:

    1. In the Azure portal, navigate to your Front Door resource.
    2. Select the Custom domains tab and then select Add custom domain.
    3. Enter the domain name for your WordPress site and select Add.
    4. Select the domain name you just added and then select the TLS/SSL settings tab.
    5. Select the Managed certificate option and then select the free Azure SSL certificate from the drop-down list.
    6. Select Save to apply the changes.

    Your WordPress site should now be able to use your SSL certificate with Azure Front Door to redirect HTTPS traffic.

    Some possible errors you could encounter when using a free Azure SSL certificate with Azure Front Door to redirect HTTPS traffic for a WordPress site hosted on Azure include:

    1. Invalid certificate: This error occurs when the certificate you are using is not valid or has expired.
    2. Certificate not trusted: This error occurs when the certificate you are using is not trusted by the web browser.
    3. Certificate not issued by a trusted authority: This error occurs when the certificate you are using is not issued by a trusted certificate authority.
    4. Certificate not installed on the server: This error occurs when the certificate is not installed on the server where the WordPress site is hosted.
    5. Incorrect routing rules: This error occurs when the routing rules you have configured are incorrect or do not match the expected behavior.

    To avoid these errors, it is important to ensure that the certificate you are using is valid, trusted, and issued by a trusted authority. You should also ensure that the certificate is installed on the server and that the routing rules are configured correctly.

    These steps are from these Azure documents:

    https://learn.microsoft.com/en-us/azure/frontdoor/front-door-custom-domain-https

    https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-bindings

    https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-certificate?tabs=apex%2Cportal

    WordPress Blog Post:https://wordpress.org/support/topic/wordpress-behind-azure-front-door-too-many-redirects/#:~:text=Yes%2C%20if%20WP%20gains%20control%20and%20the%20requested,in%20wp-config.php%20to%20prevent%20WP%20from%20redirecting%20back.

    Hope that helps. Please let us know if you have further questions

     

    Thanks,

    Grace

    1 person found this answer helpful.
    0 comments No comments

  2. Haseeb Alam 5 Reputation points
    2023-06-26T17:50:57.8966667+00:00

    In the Configuration settings, add "index.php" to the Default documents field.

    On Redirects settings and create a new redirect rule.

    Set the source as "/(.*)" to match any URL on your website.

    Set the destination as "https://example.com/$1", replacing "example.com" with your domain. Enable the "Permanent (301)" checkbox.

    This will redirect www.example.com to example.com. Clear your browser cache and test it. No coding is required, and it's suitable for non-technical users.

    1 person found this answer helpful.
    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.