Skip to content

Support some sort of URL rewriting in Drapache #2

@gnrfan

Description

@gnrfan

A simple URL rewriting mechanism would be very very welcomed. The good news is it's perfectly safe to add URL rewriting to Drapache and I will surely enable certain kinds of apps and scripts to be much more easily written this way.

Something with all of the power of mod_rewrite in Apache would be cool but I guess we don't need it since we got Python, right?

How about redirecting all 404s to a top level _rewrite.dbpy script if it's present?

Once you have that you would only need to provide us with a way to read the original requested path and we can put together our own pattern matching and URL rewriting mechanism.

Here's some code sample to help illustrate the idea:

import re

request = dbpy.http.get_request()

m = re.compile('^/posts/(?P<post_id>\d+)$')

if m.matches(request.redirect_uri):
post_id = m.groupdict()['post_id']
dbpy.http.redirect('/read_post.dbpy?post_id=%d' % post_id)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions