2

I'm developing a custom module. The module has to respond to requests on domain.com/file.txt.

How can I configure a router for this path in etc/config.xml?

This is different from the usual router configuration XML, because there is no frontname and no controller in the path.

3

You're better off using a custom Router controller for that. Inchoo and Atwix have both tutorials describing how to do this.

The one from Atwix explains the easiest. Your Router.php would look something like this

class [Namespace]_[Module]_Controller_Router extends Mage_Core_Controller_Varien_Router_Standard
{
    public function match(Zend_Controller_Request_Http $request)
    {
        if ($request->getPathInfo() == 'file.txt')
        {
           $request->setModuleName('[module]')
               ->setControllerName('index')
               ->setActionName('index');

           return true;
        }
        else
        {
            return parent::match($request);
        }
    }

}
| improve this answer | |
  • 2
    One side-note, this only works if file.txt doesn't exist, or is explicitly rewritten to Magento's index.php. So if it doesn't seem to work, check for it's existence. – Melvyn Apr 9 '14 at 20:53
  • @Melvyn Depends on the server configuration. I redirect all requests to index.php, disregarding any file existence. – i.amniels Apr 11 '14 at 10:53
  • @i.amniels I assume you make exceptions for /skin, /js and /media at least. :) – Melvyn Apr 11 '14 at 18:43
  • @Melvyn No, those are handled by the CDN. – i.amniels Apr 13 '14 at 14:43
1

You can think about a url_rewrite for this. Just add a rewrite, then magento will resolve the correct controller for you!

| improve this answer | |

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.