About Domain Redirection to WWW or Non-WWW
To redirect non-www requests to www, use this Nginx configuration:
server {
listen 443 ssl;
server_name example.com www.example.com;
charset utf-8;
if ($host ~ ^(?!www\.)(?<domain>.+)$) {
return 301 $scheme://www.$domain$request_uri;
}
# SSL certificate and other directives...
root /var/www/html;
index index.html;
}
server{
listen 80;
server_name example.com www.example.com;
location /.well-known/acme-challenge {
root /var/www/letsencrypt;
try_files $uri $uri/ =404;
}
location / {
return 301 https://$server_name$request_uri;
}
}
To redirect from www to non-www, replace the condition to this one:
if ($host ~ ^www\.(?<domain>.+)$) {
return 301 $scheme://$domain$request_uri;
}
Django/Python Consulting
If you have a specific Django challenge or integration you'd like to solve, I'd be happy to help. Book a free 30-minute call to discuss your project, see if we're a good fit, and explore the best approach for your needs. After the call, you'll receive a tailored cost estimate based on what we discuss.
Also by me
Django Messaging
For Django-based social platforms.
Django Paddle Subscriptions
For Django-based SaaS projects.
Django GDPR Cookie Consent
For Django websites that use cookies.