Rewrite url using config.xml in magento

magento

To rewrite url using config.xml file in magento. We are insert below code to tab <global> in etc/config.xml file of you module.

Wherein: 

  • Package name: khactung
  • Module name: test
  • Url before rewrite: oldurl, oldurl/ticket
  • Url after rewrite: newurl, newurl/post

 

</global>
    <rewrite>
         <!--rewrite url for controller (oldurl to newurl)-->
         <storexy_test>
              <from><![CDATA[#^/newurl/#]]></from>
              <to><![CDATA[/oldturl/]]></to>
              <complete>1</complete>
         </storexy_test>
         <!--rewrite url for function (oldurl/ticket to newurl/post)-->
         <storexy_test>
              <from><![CDATA[#^/newurl/post/#]]></from>
              <to><![CDATA[/oldturl/ticket/$1]]></to>
              <complete>1</complete>
         </storexy_test>
    </rewrite>
</global>

Some example after rewrite:

  • oldurl/ticket/          -> newurl/post/
  • oldurl/ticket/data  -> newurl/post/data
  • oldurl/ticket/123   -> newurl/post/123