Created
June 8, 2012 14:34
-
-
Save iurisilvio/2895930 to your computer and use it in GitHub Desktop.
Redirect with StripPathMiddleware
This file contains hidden or 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
# 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