• Ok I have a serious problem with the Pagenavi plugin.

    People use the pagenavi to enter queries like
    /page/number?q=Berlusconi
    /page/number?q=evilaliv

    The latter one is a spam thingy you need to install mod_security to block it. Anyway, I want to ONLY allow /page/number .. no queries whatsoever.

    How would I do that?

    Yes, Google indexes the queries, that’s why I want to disable them.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Little update on this if someone has the same error:

    This will redirect the query q=*anything* to index.php
    RewriteCond %{QUERY_STRING} q=(.*)
    RewriteRule ^(.*)$ $1? [L,NC,R=301]

    This will already help, but I want to redirect it to the correct page instead of index.php

    Also put this into robots.txt (unconfirmed)
    Disallow: /page/*?*
    Disallow: /page/*?q=*
    Allow: /page/*

    This could possibly block all /page/ sites.. I’m still testing this. If Google works as I think it does it should index all /page/1 /page/2/ but not /page/1?q=query

    I’m slowly starting to understand mod_rewrite rules. Here are the final rules that I put together:

    Final rules
    RewriteCond %{QUERY_STRING} ^[A-Za-z0-9-]=(.*)
    RewriteCond %{REQUEST_URI} /page/[0-9]/?
    RewriteRule ^(.*) $1? [L,NC,R=301]

    Put above:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    I use two conditions,
    (1) whenever there is a query string using letters or characters a-z
    (2) whenever the requested URI is /page/number between 1-999)
    then rewrite to last $1 request permanently

    I’ll probably remove the lines from robots.txt ..and I might change the second condition to remove all query strings after verifying that I don’t need them.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to rewrite /page/x?q=query to /page/x’ is closed to new replies.