Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
Best Method to Mass Convert WordPress URLs to new URL structure?

I have a plan laid out to migrate my 30k+ posts WordPress site to a custom site built by me. One of the main contention points I have is SEO and I'm pretty sure I need to properly forward all of my post URLs if I don't want to decimate my SEO on Google (which is doing extremely well for me).

Current Structure: https://ygoprodeck.com/xyz-rank-up-shark/

New Structure: https://ygoprodeck.com/deck/xyz-rank-up-shark

This part is easy as I can build the new URLs using the post_name column from WordPress in the new Database and simply redirect the old URLs to the new /deck/ URLs. However, how can I make the forwarder differentiate between posts and pages?

Take this example:

Current Structure: https://ygoprodeck.com/ritual-summoning-the-underdogs-greatest-hits/

New Structure: https://ygoprodeck.com/article/ritual-summoning-the-underdogs-greatest-hits/

I'm not entirely sure how my forward will know to redirect to /deck/ or redirect to /article/ ?

The only solution I can think of is manually redirecting each 30k+ URL which seems like a monumental task to me.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Something like this:

$file = wp_get_upload_dir() . 'rules.txt';
$open = fopen( $file, "a" );

args = array('post_type' => 'post', 'posts_per_page' => -1 );
$posts = new WP_Query($args);

if( $posts->have_posts() ){
    while( $posts->have_posts() ){
        $posts->the_post();
        global $post;

        $permalink = get_permalink($post->ID);
        //Assuming each post has only 1 category
        $category =  get_the_category($post->ID)[0]->name;

        $write = fputs( $open, 'Redirect 301 ' . $permalink . ' /' . $category . $permalink. '\n' );
    }
    flocse( $open );
    wp_reset_query();
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!