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)