Reputation: 14124
There is a url:
/foo
I would like everything to get redirected like this:
/foo/xxx --> /bar/xxx
/foo/xxx/yyy --> /bar/xxx/yyy
How does Django url-pattern has too look like to redirect all foo to bar?
Something like this?
url(r'^foo/????$', RedirectView.as_view())
This is what I was using for "zero-level" redirects and it works:
url(r'^foo/?$', RedirectView.as_view(pattern_name='template_name'))
Upvotes: 1
Views: 41
Reputation: 368894
Capture the rest part of the path in the url pattern.
And pass the path combined with /bar/
to redirect
function:
url(r'^foo/(.*)', lambda request, path: redirect('/bar/' + path))
Upvotes: 1