Created
April 9, 2018 13:37
-
-
Save m5wdev/015a516aa4c4ada4e413b6d705023c76 to your computer and use it in GitHub Desktop.
Flask redirect from www to without www
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Redirect without WWW | |
from urllib.parse import urlparse, urlunparse | |
@app.before_request | |
def redirect_without_www(): | |
urlparts = urlparse(request.url) | |
if urlparts.netloc == 'www.YOUR-DOMAIN.com': | |
urlparts_list = list(urlparts) | |
urlparts_list[1] = 'YOUR-DOMAIN.com' | |
return redirect(urlunparse(urlparts_list), code=301) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment