301 重定向旧 osCommerce 链接的最佳方法
我们正在从旧的 osCommerce 安装迁移到 WordPress。 90% 的流量来自有机结果,并且拥有超过 4,000 个索引产品页面,重定向到新网站至关重要。
旧站点的 URL 结构:
/product_info.php?cPath=1&products_id=4
其中 cPath
=> osCommerce 类别和 products_id
就是这样。这两个都包含在 osCommerce DB 中
新站点:
/categoryname/product-title
自从我们从 ID 转向永久链接以来,将所有这些 URL 动态 301 到正确位置的最佳方法是什么?我在想也许有一个 PHP 脚本来生成 .htaccess 文件,有人有这方面的经验吗?我可以将类别 ID 映射到正确的 WordPress 类别 slug,并抓取旧网站以将旧产品 URL 与产品标题相匹配。这是最好的方法/甚至可能吗?我在这里用头撞墙。
我已经看过这个,但它不适用,因为我试图动态重定向所有旧产品,或者至少动态生成重定向(就像我说的,大约 5000 个产品) 重写 htaccess 旧 oscommerce 链接
编辑: 我的想法:
1 . 创建 .htaccess 文件。
RewriteCond %{REQUEST_URI} ^/product_info\.php$
RewriteCond %{QUERY_STRING} ^cPath=([0-9]+)&products_id=([0-9]+)
RewriteRule ^(.*)$ http://www.domain.com/redirect.php?cat=%1&product=%2? [R=301,L]
2. 它将所有匹配的请求发送到自定义 php 301 重定向脚本
3. 脚本包含一系列 category_names =>; id 对
已映射到正确的数据库值(无数据库调用),以及一个单独的products_names => 数组。 Product_ids
4. 匹配类别和产品信息后,脚本会将您推送到正确的位置:
$yourNewLocation = $cat . '/' . $product . '/';
function return_301($yourNewLocation){
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: '. $yourNewLocation);
}
可能瓶颈:5000+的关联数组?与 mysql 连接获取所需信息相比,这是一个主要瓶颈吗?
We are in the process of migrating from an old osCommerce install to WordPress. 90% of the traffic is sent from organic results, and with over 4,000 indexed product pages, redirecting to the new site is essential.
The old site's URL structure:
/product_info.php?cPath=1&products_id=4
where cPath
=> osCommerce category and products_id
is just that. both of these are contained in the osCommerce DB
The new site:
/categoryname/product-title
What's the best way to dynamically 301 all of these URLs to the right place since we are moving from IDs to permalinks?? I was thinking maybe a PHP script to generate the .htaccess file, does anyone have experience with that? I can map the category IDs to the correct WordPress category slug, and scrape the old site to match the old product URLs with the product title. Is this the best way/even possible? Banging my head against a wall here.
I've looked at this but it doesn't apply because I'm trying to redirect all of the old products dynamically, or at least generate the redirects dynamically (like I said, about 5000 products)
Rewrite htaccess old oscommerce links
EDIT: My idea:
1. Create .htaccess file.
RewriteCond %{REQUEST_URI} ^/product_info\.php$
RewriteCond %{QUERY_STRING} ^cPath=([0-9]+)&products_id=([0-9]+)
RewriteRule ^(.*)$ http://www.domain.com/redirect.php?cat=%1&product=%2? [R=301,L]
2. It sends all matching requests to a custom php 301 redirect script
3. Script contains an array of category_names => id pairs
already mapped to the correct database values (no database calling), and a separate array of products_names => product_ids
4. After matching the category and product information, the script pushes you to the right place:
$yourNewLocation = $cat . '/' . $product . '/';
function return_301($yourNewLocation){
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: '. $yourNewLocation);
}
Possible bottlenecks: associative arrays of 5000+? is that a major bottleneck vs a mysql join to get the needed info?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“我在想也许可以使用 PHP 脚本来生成 .htaccess 文件”
如果您打算这样做,我建议将重定向放在 httpd include 而不是 .htaccess 中,这样会对性能造成影响当使用 .htaccess 时 - 在这方面包含可能会更好。
另外,如果您要使用 php 将 id 映射到永久链接:
我不能 100% 确定您的计划是否是“最好的方法”,但它听起来确实合理..(当然,使用 php + 数据库调用动态重定向将是比 .htaccess 或 include 方法更受欢迎!)
"I was thinking maybe a PHP script to generate the .htaccess file"
If you are going to do that, I suggest placing your redirects in an httpd include rather than the .htaccess, there is a performance hit when using .htaccess - an include will probably be be better in that respect.
Also if you are going to map ids to permalinks using php:
I'm not 100% sure if your plan is 'the best way' but it certainly does sound reasonable.. (of course redirecting dynamically with php + a database call will be more of a hit than wither .htaccess or include methods!)