I see loads of tutorials about naked domain to
www domain redirects, but what if I want to do it the other way around (
My app is on Google Apps with Flask deployed, and my domain is registered with GoDaddy.
If you do want to redirect, you could try this untested snippet of slightly modified code from https://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 = 'example.com' redirect(urlunparse(urlparts_list), code=301)