Ad

Redirect Old Url To New Url With Django

- 1 answer

I changed my website url to new one , but google is showing my old url , i have read that i need to make 301 redirect to help google to show my new url, but i don't know how to make it with django!

my old url :

path('<int:pk>/', views.ArticleDetail.as_view(), name='detail')

my new url :

path('<int:pk>/<slug>', views.ArticleDetail.as_view(), name='detail')

more info : i'm using nginx

Ad

Answer

There are a few things you need to do to make sure that your website gets crawled properly.

In regards to the redirection, you can use django.http.HttpResponsePermanentRedirect to perform the redirection. Just keep the view, and when a user navigates to this view, redirect them to the proper URL.

You should also create a sitemap, which lists out all of the URLs for your website. You can then submit this sitemap to google using their webmaster tool if you have not already done so. This will inform their crawler of all the pages that they need to crawl without worrying on them missing some information.

Ad
source: stackoverflow.com
Ad