skip to Main Content

We’ve changed our permalink-structure from /archive/%post_id% to /%year%/%monthnum%/%postname%/ for better SEO.

Now we have the problem, that all old URLs on Facebook for example are pointing to a 404 page.

Is it possible to rewrite the old URLs to the new format?

4

Answers


  1. Chosen as BEST ANSWER

    Added the following code to my themes functions.php

    // Adding a new rule
    /**
     * Adds a new rewrite rule.
     *
     * @param array $rules Existing rewrite rules.
     * @return array (Maybe) modified list of rewrites.
    */
    function wpdocs_insert_rewrite_rules( $rules ) {
        $newrules = array();
        $newrules['archive/(d*)$'] = 'index.php?postname=$matches[1]&post_id=$matches[2]';
        return $newrules + $rules;
    }
    add_filter( 'rewrite_rules_array','wpdocs_insert_rewrite_rules' );
    
    // Adding the id var so that WP recognizes it
    function wpdocs_insert_query_vars( $vars ) {
        array_push( $vars, 'id' );
        return $vars;
    }
    add_filter( 'query_vars','wpdocs_insert_query_vars' );
    

  2. Will be better to make redirection 301 from old to news.
    Several rules in the .htaccess should work.

    Login or Signup to reply.
  3. I think you can use plugin “Simple 301 Redirects” to redirects from your old URLs to your new URLs.
    You can dowload it at here https://wordpress.org/plugins/simple-301-redirects/

    Login or Signup to reply.
  4. If you need to 301 old URLs to the new, a WordPress plugin called ‘Eggplant 301 Redirects’ works really well.

    https://wordpress.org/plugins/eps-301-redirects/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search