magento Url重写方法

用户友好的Url重写是所有网站都需要的一个功能,在magento系统中,实现URL重写有多种方法,下面这几个方法的url重写优先级是逐渐降低的,也就是说方法1要比方法2先执行

1、在后台的catalog->url rewrite management 中添加自己的URL重写

在这里添加的url 重写都是静态的,一对一的,而添加的url都会存储到core_url_rewrite表中


2、根据模块的配置文件config.xml中的控制器重写配置对url重写

<global>  
<rewrite>  
    <corerewrite_tag_productList>  
        <from><![CDATA[#^/tag/product/list#]]></from>  
                       <to>/corerewrite/tag/productList</to>  
    </corerewrite_tag_productList>  
    <corerewrite_tag_test>  
        <span style="color:#33ccff;"><from><![CDATA[#^/test#]]></from><!--还支持正则--></span>  
                       <to>/corerewrite/tag/test</to>
  <complete>1</complete>
    </corerewrite_tag_test>  
     </rewrite>  
       </global>  

3、添加自定义的路由来对URL重写,添加自定义路由的方法是在自己模块的config.xml中添加如下格式的配置

<default>  
<web>  
            <routers>  
                <admin>  
                    <area>admin</area>  
                    <span style="color:#3366ff;"><class>Mage_Core_Controller_Varien_Router_Admin</class></span>  
                </admin>  
                <standard>  
                    <area>frontend</area>  
                    <span style="color:#3366ff;"><class>Mage_Core_Controller_Varien_Router_Standard</class></span>  
                </standard>  
            </routers>  
</web>  
</default>  


4、通过控制器的_rewrite()方法重写,配置格式是在config.xml中添加如下格式的配置

* Example of configuration:
     * <global>
     *   <routers>
     *     <core_module>
     *       <rewrite>
     *         <core_controller>
     *           <to>new_route/new_controller</to>
     *           <override_actions>true</override_actions>
     *           <actions>
     *             <core_action><to>new_module/new_controller/new_action</core_action>
     *           </actions>
     *         <core_controller>
     *       </rewrite>
     *     </core_module>
     *   </routers>
     * </global>
     *
     * This will override:
     * 1. core_module/core_controller/core_action to new_module/new_controller/new_action
     * 2. all other actions of core_module/core_controller to new_module/new_controller
     *



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值