Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

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.

share|improve this question
    
Why not use this? magentocommerce.com/magento-connect/… –  B00MER Apr 9 at 21:40

2 Answers 2

up vote 3 down vote accepted

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

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

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

share|improve this answer
1  
Or Fabians route byte.nl/blog/create-bulk-301-redirects-in-magento –  B00MER Apr 9 at 21:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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