WordPress permalink redirect problem – SitePoint

down vote
I recently changed my permalink structure and I’m in a bit of a pickle. The original permalink structure was /%postname%-%post_id%/ and I wanted to change it to /%postname%/.

The rule is something like this

RedirectMatch 301 ^/dir/([^/]+)-(d+)/$ http://example.com/dir/$1

While the above code works, I encountered a problem where some articles that end in digits, are incorrectly redirected and the site gives an error. For example: www.site.com/best-video-converters-windows-10/. The rule cuts away the 10 bit, making the article 404. I found a workaround by using a regex limiting the number of chars and the code is:

RedirectMatch 301 ^/dir/([^/]+)-(d+){3,}/$ http://example.com/dir/$1

And this code works…unless the article doesn’t end in a year or something. Example: www.example.com/best-movies-2017/

Bottom line, I have no idea how to get around this and I need a bit of help :slight_smile:

Source link

قالب وردپرس

Leave a Reply