Hello @Aj to achieve your redirection for http://bob.com, https://bob.com, and https://www.bob.com, you can follow these steps:
- In the WordPress admin dashboard, go to "Settings" > "General" and ensure that the "WordPress Address (URL)" and "Site Address (URL)" fields are set to "https://www.bob.com".
- 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.
- 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 aswp-config.php
). b. Add the following code to theweb.config
file:
This<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Redirect to HTTPS" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> </rule> <rule name="Redirect to www" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^bob\.com$" /> </conditions> <action type="Redirect" url="https://www.bob.com/{R:1}" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
web.config
file contains two rules:- The first rule redirects HTTP traffic to HTTPS.
- The second rule redirects non-www traffic (bob.com) to www (www.bob.com).
After making these changes, your website should be accessible via https://www.bob.com, and any requests to http://bob.com or https://bob.com should be redirected to https://www.bob.com.
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.
-Grace