Skip to content

Instantly share code, notes, and snippets.

@davidwtbuxton
Created March 23, 2021 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidwtbuxton/b083fb181a973ee43637a900fc36866f to your computer and use it in GitHub Desktop.
Save davidwtbuxton/b083fb181a973ee43637a900fc36866f to your computer and use it in GitHub Desktop.
Example of App Engine static website with Python redirect handler
runtime: python37
handlers:
# Redirect / and /my-example-project to /my-example-project/. Requires Python.
- url: /(my-example-project)?$
script: auto
secure: always
# The static assets are collected in a "dist" folder.
- url: /(.*/)?$
static_files: dist/\1index.html
upload: dist/.*index.html
secure: always
http_headers:
Strict-Transport-Security: "max-age=2592000; includeSubdomains"
X-Content-Type-Options: "nosniff"
X-Frame-Options: "DENY"
X-XSS-Protection: "1; mode=block"
Content-Security-Policy: >-
base-uri 'none';
object-src 'none';
script-src 'self'
*.gstatic.com
*.googletagmanager.com
https://www.google-analytics.com/analytics.js;
- url: /
static_dir: dist
secure: always
http_headers:
Strict-Transport-Security: "max-age=2592000; includeSubdomains"
X-Content-Type-Options: "nosniff"
X-Frame-Options: "DENY"
X-XSS-Protection: "1; mode=block"
Content-Security-Policy: >-
base-uri 'none';
object-src 'none';
script-src 'self'
*.gstatic.com
*.googletagmanager.com
https://www.google-analytics.com/analytics.js;
import flask
app = flask.Flask(__name__)
@app.route('/')
@app.route('/my-example-project')
def redirect_home():
return flask.redirect('/my-example-project/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment