[英]How do I redirect custom url using htaccess?
I am migrating from Wordpress to a custom coded content management system and need help converting the old URLs using htaccess. 我正在从Wordpress迁移到自定义编码内容管理系统,需要帮助使用htaccess转换旧URL。
I have over 2000+ old articles with the following URL structure: 我有超过2000多篇旧文章,其中包含以下网址结构:
www.site.com/ID/post-title/ www.site.com/ID/post-title/
I need to redirect each post to a custom script that uses the post ID: 我需要将每个帖子重定向到使用帖子ID的自定义脚本:
www.site.com/post.php?id=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. 其中ID
不是固定字符串,而是作为id
值传递给脚本的变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.