Fix duplicate first page of paginated results

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from django.http import HttpResponsePermanentRedirect
from django.conf import settings


PAGE_VAR = getattr(settings, 'PAGE_VAR', 'page')


class FixFirstPaginatedPage(object):
    def process_request(self, request):
        if request.method == 'GET':
            try:
                page = int(request.GET[PAGE_VAR])
            except (KeyError, ValueError, TypeError):
                return None
            if page == 1:
                params = request.GET.copy()
                del(params[PAGE_VAR])
                path = request.path
                if params:
                    path += '?' + params.urlencode()
                return HttpResponsePermanentRedirect(path)

More like this

  1. Filter to adjust forloop.counter across pages in a paginated view by egmanoj 4 years, 2 months ago
  2. Generic Permissions by muhuk 4 years ago
  3. Pagination/Filtering Alphabetically by zain 4 years, 2 months ago
  4. Modelaware json serializer by fivethreeo 6 years, 2 months ago
  5. Pagination shortcut by piratus 4 years, 2 months ago

Comments

carljm (on September 1, 2009):

Curious if you have any actual evidence or experience that this is a real problem. I have to think that optional querystring parameters (where supplying the default value gets the same results as supplying no value) are quite common across the web, and search engines must take that into account in their duplicate content algorithms.

#

muhuk (on September 4, 2009):

@carljim I have no concrete evidence. That's why I used the word might. But I used to have pagination bit on the URL, like /some_view/1/, that is another story and this is a problem in such cases.

OTOH, there are others complaining about the same possibility.

Thanks for the inquiry. I would like to hear other opinions as well.

#

(Forgotten your password?)