本文介绍了Magento中的Gernerate自定义网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用magento生成自定义网址/路由,目前我已在本地模块中的config.xml中设置了默认路由.

I am currently looking at trying to generate custom urls/routing using magento, currently I have set a default route in config.xml within the local module.

<frontend>
 <routers>
         <portfolios>
             <use>standard</use>
             <args>
                 <module>Custom_Portfolios</module>
                 <frontName>portfolios</frontName>
             </args>
         </portfolios>
     </routers>
     <default>
         <router>portfolios</router>
     </default>
 </frontend>

当前,此方法适用于/portfolios/index/action/custom-string的url路径,这是magento的默认路由.我想要达到的目的是让/portfolios/custom-string.html尝试使用mod_rewrite规则没有成功,我发现了一些与利用.html的自定义后缀有关的参考,我将它们添加到了相同的config.xml文件.

This currently works with the url path of /portfolios/index/action/custom-string which is the magento default route.What I am trying to achieve is to have /portfolios/custom-string.html I have attempted to use a mod_rewrite rule with no success, I have found some references in relation to utilising a custom suffix of .html which I have added to the same config.xml file.

<default><portfolios><seo><portfolios_url_suffix>.html</portfolios_url_suffix></seo></portfolios></default>

我查看了与路由有关的alan storm文档,发现它仅依赖于默认路由路径,或者信息有些过时.

I have looked at the alan storm docs in relation to routing and found it relevent to the default routing paths only or the information is a little out-dated.

您是否知道最好的方法来控制magento中的路由,并可能易于遵循和相关的教程?如果是这样,请分享:D很多

Do you know the best method to control the routing within magento with possibly an easy to follow and relevent tutorial? if so please share :D many

推荐答案

执行此操作的方法是使用URL重写.实际上,您发现的后缀配置可能被Mage_Catalog用于创建其重写集.我是第一次接触这个特殊功能,因此应该在添加少量盐的情况下使用此代码段...

The way to do this is with an URL rewrite. In fact, the suffix config you found is probably used by Mage_Catalog to create it's sets of rewrites. I'm approaching this particular feature for the first time so this snippet should be taken with a pinch of salt...

// Creating a rewrite
/* @var $rewrite Mage_Core_Model_Url_Rewrite */
$rewrite = Mage::getModel('core/url_rewrite');
$rewrite->setStoreId($store_id)
        ->setIdPath('portfolios/'.$url_key)
        ->setRequestPath('portfolios/'.$url_key.'.html')
        ->setTargetPath('portfolios/index/action/id/'.$url_key)
        ->setIsSystem(true)
        ->save();

每个可能的路径都需要进行新的重写.

A new rewrite is needed for each possible path.

编辑; 我添加了setIdPath,因为可能有必要.

Edit; I've added a setIdPath because it might be necessary.

这篇关于Magento中的Gernerate自定义网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 03:46