0

Current structure is /%year%/%monthnum%/%postname%.html

Desired structure is /%postname%/

Since we are already positioned with urls like domain.com/2015/04/example-post.html, we want people to be redirected to domain.com/example-post/.

I already tried installing some plugins, like Simple 301 Redirects, which looked good since it seems to work with rules as shown in the image below:

enter image description here

But it didn't worked to us, we get 404 from old urls :(

Adding 301 rules manually is not an options since we have thousands of posts, doing it with a script would be a easy option but I don't think is optimal to have thousands of 301 rules, would it be?

Any other suggestion?

1
  • You can not use the wordpress variables in there. You can use regex but the option below would be better.
    – JpaytonWPD
    Feb 23, 2017 at 12:31

2 Answers 2

3

You don't need a plugin to achieve your goal. Use server redirect in the .htaccess file because it will not load the processor to interpret the WordPress PHP code and will not consume time. The redirect will be completed before the WordPress runs.

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

Where

  • [0-9]+/ is the numeric year and month
  • (.*) is the part we'll use below (example-post in your case)
  • /$1 is the part we've got from the above

301 redirect is completely perfect for SEO.

1
  • I already got it working with other similar rule, but thanks for your explanation, nice answer!
    – Mc Kernel
    Feb 23, 2017 at 12:36
0

This tool did the work for me: https://yoast.com/research/permalink-helper.php

there you enter the old and new permalinks structure and it gives a single rule, in mi case:

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([^/]+).html$ https://domain.com/$3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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