MaxCDN Edge Rules are a great way to ensure that your users get a consistent experience, while also mitigating possible duplicate content in your CDN cache, no matter the format used when a hyperlink is used to get to your site.
This article will cover how to solve a scenario where a trailing slash after a URI, /
, might cause issues for your users. Let's take a look!
The EdgeRules feature is available only on Enterprise plans.
Background
Having two URIs responding with the same content may lead to duplicate content, and that is penalized by search engines.
From a technical search engine standpoint, it’s certainly permissible for these two URL versions to contain different content. However your users may find this configuration horribly confusing -- just imagine if cdn.yourdomain.com/foo
and cdn.yourdomain.com/foo/
produced two separate experiences. Let's ensure that the user gets the same experience each time.
Example of the Rule
cURL Before Rule
Notice that we get a 200 response, but we don't redirect to the desired domain without a trailing slash
$ curl -I http://cdn.domain.com/example/
HTTP/1.1 200 OK
Date: Wed, 11 Nov 2015 02:47:50 GMT
Content-Type: text/html
Content-Length: 935
Last-Modified: Thu, 06 Aug 2015 12:32:59 GMT
Server: NetDNA-cache/2.2
X-Cache: HIT
Accept-Ranges: bytes
cURL After Rule
Notice we get the 301 redirect, this time to the proper domain, but without the trailing slash as shown in the Location response header.
$ curl -I http://cdn.domain.com/example/
HTTP/1.1 301 Moved Permanently
Date: Wed, 11 Nov 2015 02:36:25 GMT
Content-Type: text/html
Content-Length: 185
Location: http://cdn.domain.com/example
Connection: keep-alive
Server: NetDNA-cache/2.2
Resulting Nginx Configuration Block
This is how the configuration will look on the Edge Servers after implementing the rule. Note the regex defining the resulting rewrite.
location ^~ /example/ {
rewrite ^\/(.*)\/$ /$1 permanent;
...
}
We hope this article was helpful and as always, If you have any questions or concerns about any of the topics mentioned in this article, please feel free to reach out to support - we are available 24/7 by chat or email!