L
L
Leonid2016-05-08 16:20:39
Apache HTTP Server
Leonid, 2016-05-08 16:20:39

Redirect pages of pagination section with GET-variable?

There are addresses like:

site.ru/articles/news?page=N

where N is the page in the section, i.e. any number from 1 to infinity!
these addresses need to be redirected to an address of the form:
site.ru/news/page/N

I try like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} page=(\d+) [NC]
RewriteRule ^articles/news /news/page/%1 [R=301,L]

The redirect works, for example: it
http://site.ru/articles/news?page=2
redirects to:
http://site.ru/news/page/2?page=2
but I need the final request to be without GET variables, i.e.:
http://site.ru/news/page/2
How to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Leonid, 2016-05-08
@easycode

solution found:

RewriteCond %{QUERY_STRING} page=(\d+) [NC]
RewriteRule ^articles/news /news/page/%1? [R=301,L]

I forgot the question mark (?) at the end, though I don’t know why it’s there and what it means!

V
Viktor Taran, 2016-05-11
@shambler81

The question mark is needed, it removes the bucket at the end.
1 robots.txt - disable all queries with page=
2. real canonical to the main page
3. redirect actually ;) if from an old site
4. close page with ajax.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question