1.后台system -> configuration -> catalog -> Search Engine Optimizations
中Use Categories Path for Product URLs
2.app/code/core/mage/catalog/model/product/url.php
修改getUrl函数
if (empty($requestPath) && $requestPath !== false) {
$idPath = sprintf('product/%d', $product->getEntityId());
//以下代码注释
//if ($categoryId) {
// $idPath = sprintf('%s/%d', $idPath, $categoryId);
//}
$rewrite = $this->getUrlRewrite();
$rewrite->setStoreId($storeId)
->loadByIdPath($idPath);
if ($rewrite->getId()) {
$requestPath = $rewrite->getRequestPath();
$product->setRequestPath($requestPath);
} else {
$product->setRequestPath(false);
}
}