KingStakh KingStakh - 9 months ago 56
Apache Configuration Question

How create rule in .htaccess to redirect

Have some problem after change CMS to Wordpress. My old url-s looks like where 12123 post ID. Now my url-s looks like After migrate to WP I save in my DB old post ID's as custom field. Now I need redirect all user who comes to my site by old url's to new url's. For this I need in .htaccess add 301 redirect some like this:

Redirect 301 /news/sport/12123 /redirectold.php?oldid=12123

Where redirectold.php get from DB new url by old ID from url. If I open directly all works fine, but I don't know how redirect to /redirectold.php?oldid= all old links and get old post ID from old url and place it after /redirectold.php?oldid= in .htaccess.

E.g. if open old link need redirect it to via .htaccess


Try this,

RewriteEngine on
RewriteRule ^/news/sport/([0-9]+)$ /redirectold.php?oldid=$1 [R=301,L]