Mobile app version of vmapp.org
Login or Join
YK1175434

: How do you implement a www to naked domain redirect in Google Apps with Flask? I see loads of tutorials about naked domain to www domain redirects, but what if I want to do it the other

@YK1175434

Posted in: #Dns #Domains #Godaddy #GoogleApps #Redirects

I see loads of tutorials about naked domain to www domain redirects, but what if I want to do it the other way around (www.example.com -> example.com)?

My app is on Google Apps with Flask deployed, and my domain is registered with GoDaddy.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @YK1175434

1 Comments

Sorted by latest first Latest Oldest Best

 

@Berumen354

is an automatic alias. (See www.chickenaday.appspot.com/ vs chickenaday.appspot.com/). Why force the user?

If you do want to redirect, you could try this untested snippet of slightly modified code from stackoverflow.com/a/10964868/3164117:
from urlparse import urlparse, urlunparse
@app .before_request
def redirect_nonwww():
"""Redirect www requests to non-www."""
urlparts = urlparse(request.url)
if urlparts.netloc == 'www.example.com':
urlparts_list = list(urlparts)
urlparts_list[1] = 'example.com'
redirect(urlunparse(urlparts_list), code=301)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme