: 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
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.
More posts by @YK1175434
1 Comments
Sorted by latest first Latest Oldest Best
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)
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.