Redirects for canonical URLs
See the original post on my blog for context on how to setup edge rules in Bunny such that only the canonical URL is served for a given page.
For example, consider the about page. Without any configuration, Bunny will serve the page at the following URLs:
/about/index.html/about/about/
The canonical link element for the about page specifies that /about/ is the path in the canonical URL:
<link rel="canonical" href="http://localhost:1313/about/" />
You can setup edge rules that redirect /about/index.html and /about to /about/. These perform a 301 permanent redirect, taking care to preserve query parameters:
| Input | Output |
|---|---|
| /about/index.html | /about/ |
| /about/index.html?a=0&b=1 | /about/?a=0&b=1 |
| /about | /about/ |
| /about?a=0&b=1 | /about/?a=0&b=1 |
| /about/ | /about/ |
| /about/?a=0&b=1 | /about/?a=0&b=1 |
For the sake of a counterexample, I’ve setup the rules so that /no-redirects* bypasses the rules. As such, all three URLs serve the same page: