As we dive into the best practices and details we could gather, we stumbled upon a case where code-side settings for www to non-www redirection was unachievable. It nearly drives us nuts for hours but still to no avail. Thankfully a friend from a different project was able to give assistance when it comes down to this problem. The problem of redirecting www to non-www on an NGINX server.
Since Cloudflare is something that we are commonly using through our site setup, he was able to share his experience and found solution to us. This is through Cloudflare page rules. When all else failed, this is a solution we could definitely run to. Without further ado, let's get to the steps on how we have achieved such feat.
The steps are simple and as follows:
- Login to your Cloudflare account
- Select the desired domain
- Navigate to Rules section
- Click on Create Page Rule button
- Fill up the form as necessary and desired configuration
- Click on Save and Deploy button
There are a lot of other options you could still choose from for the kind of page rule settings you want to impose. However, perhaps it would be better for a separate topic. Do also take note that for a Free Cloudflare subscription, you may only create three (3) page rules so be careful and use it wisely.
What are your thoughts? Drop 'em on our comment section below.
Special thanks to our friend at Arkjuander for this awesome guide!