永久重定向绝对 url

Permanent redirect absolute url

我正在努力使用基本的重定向功能。

我需要将所有不匹配特定路径的流量重定向到另一个域。

在我的 urls.py

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

和views.py

中对应的函数
def myView(request, shortcode=None):
    url = 'www.newdomain.cz/' + str(shortcode)
    return HttpResponsePermanentRedirect(url)

但它的作用是 - 例如调用时 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

我错过了什么?

您需要使用完全限定的 url。

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

查看文档 here