2

I have a page named stores and I have a following rewrite:

<global>
    <rewrite>
        <designer_url>
            <from><![CDATA[#^/stores/#]]></from>
            <to><![CDATA[/storescontroller/index/index/location/]]></to>
            <complete>1</complete>
        </designer_url>
    </rewrite>
</global>

So the idea is for http://mystore.com/stores to go to the cms page and for http://mystore.com/store/dallas/ to go to the controller. How can I resolve this conflict?

THanks in advance

  • 1
    Unless you are using a thoroughly ancient version of Magento you should not be using global rewrites. – benmarks Jul 9 '15 at 12:40
2

You have three decent options besides the global rewrite you noted (it's very, very deprecated).

Possibly the easiest option is via webserver configuration (e.g. RewriteRule for Apache).

Another option would be to add a new router class with a match() method which recognizes your URL structure and can rewrite the request object just as the CMS router (Mage_Cms_Controller_Router) does:

public function match(Zend_Controller_Request_Http $request)
{
    //snip...

    $request->setModuleName('cms')
        ->setControllerName('page')
        ->setActionName('view')
        ->setParam('page_id', $pageId);
    $request->setAlias(
        Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS,
        $identifier
    );

    return true;
}

Because the request is not marked as dispatched the router loop in Mage_Core_Controller_Varien_Front::dispatch() will re-cycle and then the Standard router will match the new request structure.

Speaking of Mage_Core_Controller_Varien_Front::dispatch() - in more recent versions of Magento it is also possible through configuration to inject your own rewrite class:

public function dispatch()
{
    //snip...
    $this->_getRequestRewriteController()->rewrite();
    //snip...
}

$this->_getRequestRewriteController() reads the value at global/request_rewrite/model, which you can overwrite with your own value. You can extend the Mage_Core_Model_Url_Rewrite_Request class and override the rewrite() method, or you can implement your own class with a rewrite() method which detects the URL param/structure you want to use and defers to the core class.

1

Why do you need a rewrite for this? Your cms page should work if the URL listed in admin is "stores". Then within your module config.xml you can use the routers tag and assign a frontname as:

<routers>
   <frequent>
      <use>standard</use>
      <args>
        <module>xxx_xxx</module>
        <frontName>store</frontName>
      </args>
   </frequent>
</routers>

From this you could have a dallasAction in your controller which loads the desired content.

  • Obviously I need something different. 1. CMS page name and router frontName in your example need to be the same: both "stores" (this is why I emphasized that it is a conflict). 2. I need a rewrite, because I don't want to write an action for every single location - this is why I do rewrite, and pass "dallas" as parameter to controller index. – nakajuice Jul 9 '15 at 11:56
1

Instead using global rewrite, you can create the URL Rewrite in admin panel.

Navigate to

admin > catalog > Url Rewrite Management > Add Url Rewrite

Select the Custom for Url Rewrite.

Id path >> Unique id 

Requested Path >> store/dallas/

Target Path  >> /storescontroller/index/index/location/

Now

http://mystore.com/stores will goto your cms page

http://mystore.com/stores/dallas will goto the controller

Refer this

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.