简体   繁体   中英

How create rule in .htaccess to redirect

Have some problem after change CMS to Wordpress. My old url-s looks like http://example.com/news/sport/12123 where 12123 post ID. Now my url-s looks like http://example.com/12/12/2016/post-name . 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 http://example.com/redirectold.php?oldid=12123 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.

Eg if open old link http://example.com/news/sport/12123 need redirect it to http://example.com/redirectold.php?oldid=12123 via .htaccess

Try this,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM