David Louda
David Louda

Reputation: 577

Permanent redirect absolute url

I am struggling with a basic redirect functionality.

I need to redirect all traffic not matching certain paths to another domain.

in my urls.py

re_path(r'^(?P<shortcode>[\w-]+)/$', core_views.myView)

and the corresponding function in views.py

def myView(request, shortcode=None):
    url = 'www.newdomain.cz/' + str(shortcode)
    return HttpResponsePermanentRedirect(url)

but what it does is - when called for example www.olddomain.com/sdfasd it redirects me to www.olddomain.com/sdfasd/www.newdomain.cz/sdfasd but I obviously need only www.newdomain.cz/sdfasd

what am I missing?

Upvotes: 0

Views: 185

Answers (1)

Nicolas Appriou
Nicolas Appriou

Reputation: 2331

You need to use a fully qualified url.

def myView(request, shortcode=None):
    url = 'http://www.newdomain.cz/' + str(shortcode)

See the doc here.

Upvotes: 2

Related Questions