• Hi:

    I just changed my permalink structure from /yyyy/mm/post-slug to /post-slug (for a variety of good reasons).

    However, my old links (external – not under my control – links to posts that contain the date string) don’t redirect.

    What is the best way to redirect the old permalink structure to the new?

    Note: I tried adding this:

    RewriteRule ^[0-9][0-9][0-9][0-9]/[0-9][0-9]/(.*) /$1 [L,R=301]

    to the .htaccess file (I’m not the best at this type of code). But this doesn’t work. It has no effect.

    Any suggestions are much appreciated!

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Your .htaccess didn’t work becuase you replaced the wrong thing at the end ?? $1 means the FIRST [0-9] so you would want $7. But here’s a better one:

    RewriteRule ^([0-9]{4})/([0-9]{2})/(.*)$ https://domain.com/$3 [L,R=301]
    Thread Starter jweinberger

    (@jweinberger)

    First, Thank you! This makes sense (and shows off my “skill” at regexps ?? )

    The Rule you offered seems to work, and validated in a tester I found (here: https://htaccess.madewithlove.be/), but still does not work on my live site.

    I included it with the standard WordPress Rewrite rules, so that my .htaccess looks like this:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteRule ^([0-9]{4})/([0-9]{2})/(.*)$ $3 [L,R=301]
    </IfModule>

    Note that I tried it with and without specifying the domain in the RewriteRule in question – same no effect.

    I also tried removing the [L] flags from the two previous RewriteRules in the hope that that might be causing Apache to stop evaluating rules (they should not be met with the URLs I’m testing, but….)

    Is there anything WordPress is doing that might affect this? Or anything else?

    Any help is much appreciated!

    Thanks!

    Thread Starter jweinberger

    (@jweinberger)

    Sorry – I fixed it!

    I found a few Apache forums that suggested moving the RewriteRule first, so I tried it and it worked!

    Here’s what I have now:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteRule ^([0-9]{4})/([0-9]{2})/(.*)$ $3 [L,R=301]
    </IfModule>

    and it works fine.

    Thanks for your help! and I hope this helps someone else… ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Changing permalink structure and redirecting?’ is closed to new replies.