在URL路径冲突的情况下,哪些实体“赢”的规则是什么
题
如果多个实体(例如类别,产品,一个CMS页面和模块名称)都尝试使用相同的SEF URL,则Magento用来决定将保存的算法或过程是什么? core_url_rewrite
带有所需的 request_path
, ,并且将附加后缀以解决冲突(例如sale-sale-123.html')。
要以另一种方式提出问题,如果CMS页面和类别都要求“销售”作为他们的URL,哪个会赢得胜利?
解决方案
艾伦·斯托姆(Alan Storm)写了一篇关于它的长篇博客文章:http://alanstorm.com/magento_dispatch_rewrites_intro
要稍微缩短一点,这一切都围绕着罚款(?)
// Go through all found records and choose one with lowest penalty - earlier path in array, concrete store
$mapPenalty = array_flip(array_values($path)); // we got mapping array(path => index), lower index - better
$currentPenalty = null;
$foundItem = null;
foreach ($items as $item) {
$penalty = $mapPenalty[$item['request_path']] << 1 + ($item['store_id'] ? 0 : 1);
if (!$foundItem || $currentPenalty > $penalty) {
$foundItem = $item;
$currentPenalty = $penalty;
if (!$currentPenalty) {
break; // Found best matching item with zero penalty, no reason to continue
}
}
}