Skip to content

Instantly share code, notes, and snippets.

@iurisilvio
Created June 8, 2012 14:34
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 iurisilvio/2895930 to your computer and use it in GitHub Desktop.
Save iurisilvio/2895930 to your computer and use it in GitHub Desktop.
Redirect with StripPathMiddleware
# Untested example of permanent redirect to strip trailing slash
# It is better than internal strip the trailing slash because of SEO problems
# Based on StripPathMiddleware recipe: http://bottlepy.org/docs/dev/recipes.html#ignore-trailing-slashes
# Some pointer: http://www.adrianworlddesign.com/Knowledge-Base/seo/Watch-out-for/Trailing-slashes
class StripPathMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, e, h):
bottle.redirect(e['PATH_INFO'].rstrip('/'), code=301)
app = bottle.app()
myapp = StripPathMiddleware(app)
bottle.run(app=myapp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment