I am migrating from Wordpress to a custom coded content management system and need help converting the old URLs using htaccess.
I have over 2000+ old articles with the following URL structure:
www.site.com/ID/post-title/
I need to redirect each post to a custom script that uses the post ID:
www.site.com/post.php?id=ID
Any help is greatly appreciated.
You may try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^/]+)/? [NC]
RewriteRule .* post.php?id=%1 [L,QSA]
It will map silently this:
http://www.site.com/ID/post-title/
To this:
http://www.site.com/post.php?id=ID
Where ID
is not a fixed string but a variable that is passed as the id
value to the script.
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.