James
James

Reputation: 739

301 redirecting pagination with get variables

I'm trying to set 301 redirects on pages that have 'page=1' in the URL to stop duplicate content issues.

e.g.

http://www.domain.com/reviews/?page=1 to http://www.domain.com/reviews/

I've tried all of the variations I can find and can't seem to get anything to work.

RewriteRule ^reviews(/)?page=1$ http://www.domain.com/reviews/ [L,R=301]

RewriteRule ^(.*)/?page=1 http://www.domain.com/reviews/ [R=301,L]

RewriteCond %{QUERY_STRING} page=1
RewriteRule ^reviews$ http://www.domain.com/reviews/ [R=301,L,NE]

None of these have worked. I'm not really sure what else to try.

There are multiple different sections of the site that I need to do this for:

reviews
news
videos
accessories
hardware

An overall solution to redirect all ?page=1 URLs to their relevant section would be best.

Upvotes: 3

Views: 646

Answers (2)

Amine Hajyoussef
Amine Hajyoussef

Reputation: 4440

the question is already answered, i just would like to mention that your rules are not working because you didn't append a trailing ? to the new url in the rewrite rule

Upvotes: 1

anubhava
anubhava

Reputation: 786001

Use this code to redirect every URI with ?page=1 to one without the query parameter:

RewriteCond %{QUERY_STRING} ^page=1(&|$) [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L]

Or else if you want to redirect ONLY /reviews URI then

RewriteCond %{QUERY_STRING} ^page=1(&|$) [NC]
RewriteRule ^(reviews)/?$ /$1? [R=301,L]

Upvotes: 2

Related Questions