Search code examples
phpregexwordpresshttp-redirecthttp-status-code-301

Reformat link structure to match Wordpress


I migrated a blog from Weebly to Wordpress and we have links in Facebook to the old URL structure Weebly used for Posts. This portion /1/post/ and .html is causing a 404 in Wordpress.

Is there a way using 301 Redirect to remove the parts of the URL that are causing the issue. Or using the template redirect hook and regex inside Wordpress to fix this?

Weebly
example.com/1/post/2016/09/some-post.html

Wordpress
example.com/2016/09/some-post/


Solution

  • Try this code in your .htaccess file:

    RewriteEngine On
    RewriteRule ^\d+/\w+/(\d+)/(\d+)/([\w\-]+).+$ /$1/$2/$3/ [L,R=301]
    

    I tested it in this website: http://htaccess.mwl.be , and it seems to work. enter image description here