You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jan Max Meyer edited this page Feb 21, 2019
·
1 revision
The request pre-processor can be used to perform rewriting and other, request-related stuff before the normal ViUR function routing will be executed.
Usually, a request pre-processor is put into the project's main file right under the deploy/ folder, and configured using conf["viur.requestPreprocessor"].
defhandleRequest(path):
""" This simple request preprocessor can be used to canalize all requests coming from several domains and 301 redirects them to a main URL. """if"X-AppEngine-TaskName"inserver.request.current.get().request.headers:
returnpathmainUrl="https://www.your-domain.com"url=server.request.current.get().request.url.lower()
ifnoturl.startswith(mainUrl):
forprotoin ["http://", "https://"]:
ifurl.startswith(proto):
forotherin ["your-domain.com", "www.your-domain.com",
"your-other-domain.com", "www.your-other-domain.com"]:
ifurl[len(proto):].startswith(other):
raiseserver.errors.Redirect(mainUrl+url[len(proto) +len(other):], status=301)
returnpathconf["viur.requestPreprocessor"] =handleRequest