1

I have built a custom extension for a client for a landing page. This extension works perfectly with everything is does but I would like to support multiple frontnames in the router so that this one extension could handle multiple landing pages. Right have I have this in the etc/config.xml

<frontend>
    <routers>
        <landingpage>
            <use>standard</use>
            <args>
                <module>Client_LandingPage</module>
                <frontName>landing-page</frontName>
            </args>
        </landingpage>
    </routers>
</frontend>

I would like to be able to something like this: landing-page/* so that it would handle any page like /landing-page/some-page or /landing-page/another-page, is there anyway to do this?

<frontend>
    <routers>
        <landingpage>
            <use>standard</use>
            <args>
                <module>Client_LandingPage</module>
                <frontName>landing-page/*</frontName>
            </args>
        </landingpage>
    </routers>
</frontend>
  • There is no such thing as a wildcard frontname. landing-page on its own is essentially a "wildcard" selector. Anything you put after landing-page/ in the URL determines which controller should be used. – Andrew Noble Feb 11 '17 at 4:38
1

You can modify it so that landing-page/foo maps to a controller with which you take the code foo, load the landing page and render it accordingly.

Add something like the following to your modules xml in global/rewrite

    <rewrite>
        <namespace_module_controllername_action>
            <from>#^/landing-page\/?(.*)#</from>
            <to>/landing-page/index/index/$1</to>
            <complete>1</complete>
        </namespace_module_controllername_action>
    </rewrite>

I think this should rewrite any requests like landing-page/super-page to Namespace_Module_IndexController:indexAction and pass the parameters along.

Once you've got the parameters in the controller, you can do what you like

  • Conditionally load the correct landing page entity
  • Add new layout handles
  • Absolutely any customisation you want really.

For more reading you can have a look at http://www.endreywalder.com/blog/magento-url-rewrite-using-config-xml-and-regular-expressions/.

  • 1
    Thank You!!!! With a quick test this seems to do what I want. – Trevor Orr Feb 13 '17 at 16:58
0

You need to develop your own custom router, instead of using the "standard" one as i can see in your XML.

The router takes the request object, and points magento at the right controller action to dispatch.

More deatils on how to do this can be read here: http://inchoo.net/magento/custom-router-in-magento/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.