0

There seem to be a few similar questions out there but I am struggling to find one that relates to what I need.

I have a custom module that has a View controller. A sample URL would be:

/our-stores/index/view/id/2

I would like to change this to something similar to:

/our-stores/this-is-a-store
or /this-is-a-store.html
or /our-stores/view/this-is-a-store

I'm sure you get the idea.

I have tried adding a url redirect as follows:

$store_url = str_replace(' ', '-', $store_model->getStoreTitle());
Mage::getModel('core/url_rewrite')
                    ->setIsSystem(0)
                    ->setOptions('RP')
                    ->setIdPath($store_url)
                    ->setTargetPath('our-stores/view/index/id/' . $store_model->getId())
                    ->setRequestPath($store_url)
                    ->save();

This seems to partially work; if I go to /this-is-a-store it goes to the correct page by changes the URL in the address bar back to /our-stores/index/view/id/2

Can anyone please help me with a nice, clean way of achieving what I need?

If you need anything off me, please ask and I will provide.

1

So I figured it out myself and thought I'd share for anyone else who stumbled on this issue.

I simply changed the code in the question to:

$rewrite
    ->setIsSystem(0)
    ->setIdPath('store_' . $store_model->getId())
    ->setTargetPath('our-stores/view/index/id/' . $store_model->getId())
    ->setRequestPath($store_url)
    ->save();

The change that made the difference was not setting options to 'RF'.

0

you can rewrite the url in magento admin panel itself.

Type - Custom 
Request path – /our-stores/index/view/id/2 
Targeted path - /our-stores/this-is-a-store

you can refer this link also rewite

  • This seems to only work for categories and static CMS pages. Like I mentioned in my question, this is for a custom extension. I will need the pages to be created programmatically – Wildcard27 May 4 '16 at 6:14
  • No. you can add your own page url also same as you do for CMS page and product. it will be redirected. Try it – Manikandan May 4 '16 at 6:23

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.