dtar
dtar

Reputation: 1669

Django GET parameters redirect

I'm in process of migrating my website to Django cms. But there is a problem with the URL's with GET parameters in CMS module which has been deleted in the current site. They are still live in Google.Webmasters.

When I go to site.com?foo=0&bar=1517 it will open index page without any redirects.

Any GET parameters could spawn a duplicate page. I think it is bad for the SEO, because now I have bunch of duplicate urls for the index page.

I want to redirect all urls with get parameters from the root to my root index, ex:

site.com?foo=0&bar=1234
site.com?foo=12&bar=1234&baz=123
site.com?foo=12

  redirect(301) to:

to site.com/

Upvotes: 1

Views: 135

Answers (1)

Mohammad Etemaddar
Mohammad Etemaddar

Reputation: 463

Add this line to the beginning of your index view:

from django.shortcuts import redirect
if request.GET.get('foo') or request.GET.get('bar'):
        return redirect('/')

Upvotes: 1

Related Questions