Heroku + Django + Dnsimple - How Do I redirect www

2019-07-06 16:56发布

问题:

Hi i have a django site on Heroku with Dnsimple to manage DNS. I am also using Django to force HTTPS.

I am trying to follow google protocol so that I only have one domain

https://example.com

So that if a user visits http://www.example.com or https://www.example.com it will redirect to https://example.com

My settings in Dnsimple look like this:

ALIAS   example.com     example.com.herokudns.com
CNAME   www.example.com  example.com.herokudns.com

I tried deleting the cname and using the URL redirect in Dnsimple, but it isn't working.

Can someone let me know the correct way to do this redirect? I've tried creating a middleware based on another outdated post, but it crashed my site. Looking for the right way to do this. Thanks