0

i changed my wp theme and i changed the "post per page" wp setting on "reading"now because i want to display more posts on the archives pages. i m using pagination on the archives so a lot of pages disappeared. now google web master tools is showing me a lot of 404 errors.

For example, /author/max/page/150/ now 404s. There are many of these across numerous folders (/author/, /category/, etc.)

I cannot simply redirect /page/ as (for example) /author/max/page/100/ is a valid page.

What I would like to do is to say, "if */page/xxx = 404, then redirect to /page/", or something like that, but I'm unclear on how to proceed.

i think i need to redirect the 404 errors to a working page by an htaccess rule.

  • That is totally normal. I you had a existent URL (i.e. /author/max/page/150/) that doesn't exist anymore, 404 status code is the correct code. Don't worry about that. The problem would be that a non-existant URL returns a status code different than 404. I really don't see any advantage of making the redirection you plan to do; note that you are talking about pagination URLs, not URLs of "real" content. If you change the URL of post, the redirection is a must, but for pagination URLs I think is worthless. – cybmeta May 24 '15 at 9:44
  • i found a function that do that, i posted it below. so do you think is better to don't do that? i would delete all the errors on Web master tools. do you think redirecting it to the first page of the category could damage SEO? do you think is better to leave 404? – Amaca May 24 '15 at 18:18
  • You need to understand that 404 is the correct status code in some situations; having 404 errors in Webmaster tools can help you to identify problems in your site. For example, if valid URLs return 404 code, it is a problem. But if non-valid URLs return 404, is simply good, just ignore them. What if I post a wrong URL here to your site? You will see a 404 error in WMT, and it is just fine. Redirections should be done only when the content has been moved from one location to another. – cybmeta May 24 '15 at 18:41
  • In your case I would just ignore the 404 errors from old pagination URLs; note that pagiantion URLs should be considered as one single list because the only purpose if to provide access to the item list. Additionally, while the number of items grow, you will need again the old pagination URLs be accesible and not redirected. – cybmeta May 24 '15 at 18:42
0

i found a solution with no use of htaccess but using the WP function wp_redirect. copy and past on functions.php

function redirect_paginated_404() {
    if (is_404()) {

       $url = $_SERVER['REQUEST_URI']; //read the url
       $search = '/page/'; //chose the word of the url

       if ( strpos( $url, $search ) !== false ) { //if i find the string /page/

       //search the string /page/ in the url and delete everything after it, so the incorrectly page number
          $short = substr($url, 0, strpos( $url, $search)); 

          wp_redirect( $short, '301' ); // redirection function with the first page of category
                     exit;
                }
            }
        }
         add_action('template_redirect', 'redirect_paginated_404');

actually i don't know if could damage SEO or not, but the redirection is working fine. What do you think about it? is it better to leave the 404 error or i can use something like this?

source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.