Mobile app version of vmapp.org
Login or Join
Phylliss660

: Redirect all paginated pages to their main category page I want to redirect all the paginated pages of the category pages to their respective category pages, because I don't want google to crawl

@Phylliss660

Posted in: #301Redirect #Htaccess #Redirects

I want to redirect all the paginated pages of the category pages to their respective category pages, because I don't want google to crawl the paginated pages.

If my paginated category page URL is:
example.com/category/cat-name/page/4/

I want to redirect to:
example.com/category/cat-name/

This case can be anything from different page numbers to different category names.

How can I achieve that using .htaccess?

I'm running a WordPress site and already there are several redirects active:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^[0-9]+/([^/]+/[^/]+/?)$ / [L,R=301,NE]
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress


EDIT

First of all, some of my .htaccess rules are based on this StackOverflow Q&A. Because I need 'em to be there.

So, after your comments, I got the point. With such a redirection in action my paginated pages won't be accessed ever, even after a hard-coded URL. Yes, that'd be a mess.

Actually, you know WordPress category pages are auto generated with the number of posts. Suppose, in "Astronomy" category I got 32 posts and in each page I'm showing 10, then there would be 4 pages (10+10+10+2). Eventually I deleted two of the posts or recategorized them to another category. So the fourth page become orphan. Google crawls and got a 404. It's a continuous process and looking for such 404 hits is a critical matter for me. So I's looking for a solution.

What can I do for such problem?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Phylliss660

1 Comments

Sorted by latest first Latest Oldest Best

 

@Hamaas447

Edit 2

Based on @w3d comment and more information provided by Mayeenul:

Replace your regex:
RewriteRule ^[0-9]+/([^/]+/[^/]+/?)$ / [L,R=301,NE]
with this one:

Add this new rule:

RewriteRule ^([^/]+)/([^/]+)/page/[0-9]+/?$ /// [R=301,L]


So your .htaccess should look like:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/([^/]+)/page/[0-9]+/?$ /// [R=301,L]
RewriteRule ^[0-9]+/([^/]+/[^/]+/?)$ / [L,R=301,NE]
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress


This is assuming your url will allways contain page as its third url segment and numbers for pages. If it wont then replace it by [^/]+, it will be better (for matching) and easier if you keep this segment just like it is right now.

You can test htaccess rules on this tool.

You can use some alternatives to letting know bots you don't want these pages been crawled: you can block them using robots.txt, another way will be adding authentication.

You should not use redirects for preventing Google indexing (you said crawling maybe you meant indexing) your pages if they are useful for your visitors. If you 301 redirectem your visitors will never see them again, they will always get your non-paginated category. But if that's precisely what you're trying to do, then redirects are the answer.

If you are concerned about duplicate content, you should include <link rel="canonical" href="http://example.com/category/cat-name/" /> on each one of your paginated category pages. For this option you should not implement redirects.

Edit 1

If you're going to add a view all page, i.e. your main category page showing all items, its recommended to use rel="canonical" pointing from paginated pages to view all page.
If you're not going to add a view all page, i.e. you're going to keep all your paginated pages and not adding a main category page with all items, then you should use rel="prev", rel="next", as @Max pointed out.

Edit 3

If Google Webmaster Tools is reporting 404 errors and they really are 404's, you could let them just like they are if that doesn't bother you, eventually Google will drop those URLs from its index.
If 404 errors bothers you then implement 301 redirects if there's a new location for those URLs.
You may write a PHP script that intercepts the request and redirect when necessary, I don't know where this code should be put in WordPress' code, I'm not a WP expert.

Another option is to add those nonexistent URLs to your .htaccess and redirect them one by one. As your example example.com/category/cat-name/page/4/ no longer exists, then you .htaccess should be something like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^category/cat-name/page/4/?$ /category/cat-name/ [R=301,L]
RewriteRule ^([^/]+)/([^/]+)/page/[0-9]+/?$ /// [R=301,L]
RewriteRule ^[0-9]+/([^/]+/[^/]+/?)$ / [L,R=301,NE]
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme