用户友好的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>
* 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
*