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.

1

2 Answers 2

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);
        }
    }

}
4
  • 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.
    – user4351
    Commented Apr 9, 2014 at 20:53
  • @Melvyn Depends on the server configuration. I redirect all requests to index.php, disregarding any file existence.
    – i.amniels
    Commented Apr 11, 2014 at 10:53
  • @i.amniels I assume you make exceptions for /skin, /js and /media at least. :)
    – user4351
    Commented Apr 11, 2014 at 18:43
  • @Melvyn No, those are handled by the CDN.
    – i.amniels
    Commented Apr 13, 2014 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!

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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