Reputation: 101
I'm having some problem with a rewrite rule. I have a website that accepts as parameter a paging options, as parameter in any position
index.php?page=2
index.php?other_parameter=other_value&page=2&another_paramenter=another_value
Now problem is that some crawlers use to append all the parameters they can see on the page, so they try
index.php?page=2&page=3&page=4
index.php?other_parameter=other_value&page=2&page=3&page=4&another_paramenter=another_value
I'd like to block these second attempts, so basically block any call that has in the query parameters more than one instance of page=NN, possibly redirecting them to homepage.
I'm using https://technicalseo.com/tools/htaccess/ to test some regexp to match this, but I just can't seem to find a way to block any url with multiple page= parameters.
Any hint how you would do it?
Upvotes: 1
Views: 63
Reputation: 785186
You may use this rule to block such query strings:
RewriteCond %{QUERY_STRING} (?:^|&)(page=)\d+(?=&(?:.*&)?\1) [NC]
RewriteRule ^ - [F]
Regex pattern in this condition matches page=<number>
if that is followed by another instance of the page=
anywhere in the query string. If match is successful that request is denied (403).
Upvotes: 2