Mik*_*ike 4 url multilingual seo magento http-status-code-404
我有一个magento安装问题.我用过Magento ver.1.5.0.1,社区版开发本网站http://cissmarket.com/.
当我将语言从EU版本更改为法语并在此之后更改为德语时,会出现问题.对法语的更改是可以的,但是当在同一页面中我更改为德语时,我收到404错误.此外,这是Google网站管理员工具中的代404错误,当我尝试使用此链接并将其粘贴到浏览器中时,它也会出现404错误.我在Google网站管理员工具中有大约50种产品和~550 404错误.我知道问题来自我所描述的.
此外,我有一个SEO问题,因为我有这个页面用法语:
http://cissmarket.com/de/cartouches-refilables.html
当我切换到网站的德语版本时,它会带我到这个链接
http://cissmarket.com/de/cartouches-refilables.html?___from_store=fr(如果我现在尝试切换到英国,我会得到上面提到的404)
而不是去这一个:
http://cissmarket.com/de/nachfullpatronen.html
在关于magento的类别中切换商店时已经检查了这个404错误但是它与我的问题无关.
关于设置:
因此得出结论:问题是当我从一个页面切换到另一个页面时,语言的2次成功更改和错误的URL地址给出的404.
任何建议,将不胜感激.
更新:尝试了这个http://www.activo.com/how-to-avoid-the-___from_store-query-parameter-when-switching-store-views-in-magento但是在第一次语言更改时会产生404
编辑#1:
发现问题:文件languages.phtml包含此代码<?php echo str_replace ("/fr/","/de/",$_lang->getCurrentUrl()); ?>,实际上只根据相应的翻译替换了语言代码而不是整个URL.
所以适用于此
它会回来
那么有谁知道如何获得商店中其他语言的当前页面的相应URL?
编辑#2(使用@Vinai解决方案):
它适用于产品页面但不适用于该类别.
据我所知,在本土的Magento中没有这样的东西.
也就是说,您可以使用以下代码获取每个商店的当前页面URL.
$resource = Mage::getSingleton('core/resource');
$requestPath = Mage::getSingleton('core/url')->escape(
trim(Mage::app()->getRequest()->getRequestString(), '/')
);
$select = $resource->getConnection('default_read')->select()
->from(array('c' => $resource->getTableName('core/url_rewrite')), '')
->where('c.request_path=?', $requestPath)
->where('c.store_id=?', Mage::app()->getStore()->getId())
->joinInner(
array('t' => $resource->getTableName('core/url_rewrite')),
"t.category_id=c.category_id AND t.product_id=c.product_id AND t.id_path=c.id_path",
array('t.store_id', 't.request_path')
);
$storeUrls = (array) $resource->getConnection('default_read')
->fetchPairs($select);
Run Code Online (Sandbox Code Playgroud)
这将为您提供一个数组,其中数组键是商店ID,数组值是Magento基本URL 之后的请求路径,例如,假设您的法国商店的ID为1,德语商店的ID为2,您将获得:
Array
(
[1] => cartouches-refilables.html
[2] => nachfullpatronen.html
)
Run Code Online (Sandbox Code Playgroud)
然后,在foreach输出每个商店的URL 的循环中,使用
<?php $url = isset($storeUrls[$_lang->getId()]) ? $_lang->getUrl($storeUrls[$_lang->getId()]) : $_lang->getCurrentUrl() ?>
Run Code Online (Sandbox Code Playgroud)
调用$_lang->getUrl()将添加基本URL,因此您将获得每个商店的完整URL(例如http://cissmarket.com/de/nachfullpatronen.html).如果在core_url_rewrite表中找不到商店视图值,它将恢复为默认行为.
您仍然需要___store=fr查询参数,否则Magento会认为您正在尝试访问旧商店上下文中的新路径.幸运的是,getUrl()商店模型的调用会自动为您添加.
查询数据库的代码当然可以在任何地方(因为它的PHP),甚至在模板中,但请不要把它放在那里.拥有访问数据库的代码的正确位置是资源模型.我建议你创建一个资源模型并将其放在一个方法中.