You can use this document to learn how to redirect traffic from your www subdomain (www.example.com) to your apex domain (example.com), as well as HTTP to HTTPS protocol with a 301 redirect.
You can also use this document to redirect other subdomains, such as support.example.com or blog.examples.com.
Step 1: Create a rule
- In the StackPath Control Portal, in the left-side navigation, click Sites.
- Locate and select the desired site.
- In the left-side navigation, click Edge Rules.
- Click Edge Rules.
- Scroll down to Delivery Rules, and then click Add Delivery Rule.
- In Rule Name, enter a descriptive name for the rule.
- Create and save the following EdgeRule:
IF URL Matches
- Be sure to replace yourdomain with the actual domain of the website.
By setting a URL Matches condition to match
*://www*, the EdgeRule will check to see if the incoming request contains WWW at the beginning of the URL before triggering the rule. The "THEN: Redirect" will redirect the incoming request to use
https:// at the beginning of the URL to force the HTTPS protocol, and remove WWW from the URL. Additionally, it will add the Full File Path and Query String Parameters from the request with
Step 2: Verify the rule
The newly created rule will performa 301 for your domain. To verify this rule, review the headers from the CDN assets via browser inspect tools or cURL requests.
- For browser tools, right-click anywhere on your website, select Inspect or Inspect Element, and then navigation to the Network tab.
- If you do not see any requests, then request the www version of your website again; refresh the website to watch the requests.
- For cURL requests, use the option
-Ito see the headers appropriately and the option
-Lto follow the redirect automatically.
- Review the following example of a 301 status code and then a 200 without www added to the beginning of the domain.