Mr Yar
Mr Yar

Reputation: 349

How can I catch an id in static urls and redirect it to new urls in wordpress [301]

I need to redirect old urls structure to new one in wordpress with 301, here is one of my old urls

example.com/en/news/1/13005/post_title

I want to catch 13005 which is the post id and redirect url to new structured parameter base wordpress url :

example.com/?p=13005

For some reasons i might need to add a specific number to all old ids, How can i implement these redirections ?

Upvotes: 0

Views: 101

Answers (1)

Muhammad Bilal
Muhammad Bilal

Reputation: 2134

You can do this by adding following rules in your .htaccess file:

RewriteEngine On
RewriteRule ^en/news/([0-9]+)/([0-9]+)/post_title$ http://example.com/?p=$2 [R=301,L]

For dynamic post_title you can use:

RewriteRule ^en/news/([0-9]+)/([0-9]+)/(.*)$ http://example.com/?p=$2 [R=301,L]

Upvotes: 1

Related Questions