• Hello,

    I have been making some major changes to my sites structure and setup which caused me to have to make some changes to the permalinks and link structure. I thought it would be easy to add .htaccess redirect rules, but I’m running into a lot of problems. I am currently running the latest version of WordPress with the Network setting

    I’ve tried following the rules here:

    https://scott.yang.id.au/2007/02/change-wordpress-permalink/

    But I don’t think its working correctly on Network setting. This is the results I’m getting:

    When I click the old permalink:

    https://www.domainname.com/subdirectory/20101228-the-top-10-nfl-news-stories-of-2010/

    Sends me to here:

    https://www.sitename.com/?name=the-top-10-nfl-news-stories-of-2010

    These are currently the Rewrite rules I have in .htaccess:

    RewriteCond %{HTTP_HOST} !^(www)\. [NC]
    RewriteCond %{HTTP_HOST} ^(.*)\.sitename\.com$ [NC]
    RewriteRule (.*) https://www.sitename.com/%1/$1 [R=301]
    RewriteRule /[0-9]{4}/[0-9]{2}/[0-9]{2}/([^/]+)/? /?name=$1 [R,L]

    I’ve also tried the following script:

    <?php 
    
    if (have_posts()) : while (have_posts()) : the_post();
    
    $the_year = print the_time('jS');
    $the_day = print the_time('F');
    $the_month = print the_time('m');
    
    //To get the slug, use this:
    
    $post_obj = $wp_query->get_queried_object();
    $post_ID = $post_obj->ID;
    $post_title = $post_obj->post_title;
    $post_slug = $post_obj->post_name;
    
    //The put it back together:
    
    header('Location: https://www.sitename.com/subdirectory/'.$the_year.'/'.$the_month.'/'.$the_day.'/'.$post_slug.'/');
    
    endwhile; endif;
    
    ?>

    Please let me know if you have any questions.

    Thanks
    Grant

Viewing 1 replies (of 1 total)
  • Grant,

    Your question is quite unclear, especially regarding the new url pattern which you desire.
    The rules you have in your .htaccess do exactly what you say they do, so you’re basically giving it the wrong rules.

    I’ll have a guess….

    If your old urls all follow the same pattern:
    https://www.domainname.com/subdirectory/20101228-the-top-10-nfl-news-stories-of-2010/
    i.e. /subdirectory/[year][month][day]-[postslug]/

    and your new urls should look like:
    /subdirectory/[year]/[month]/[day]/[postslug]/

    Try changing the last rule in your .htaccess to:
    RewriteRule /subdirectory/([0-9]{4})([0-9]{2})([0-9]{2}-([a-z0-9-]+)/? /subdirectory/$1/$2/$3/$4/ [R,L]

    If this is not what you want, please clarify your question.

    Smile,
    Juliette

Viewing 1 replies (of 1 total)
  • The topic ‘Mod_Rewrite/Permalink Changes’ is closed to new replies.