0

what iam trying to achieve is : to redirect a cms page to home page; the cms page is accessible by domain.com/home what i need is to redirect to domain/

i had already created a custom url rewrite rule from magento admin

ID Path :home(this is the url key of the cms page & this page is accessible via domain/home)
Request Path :domain/home 
Target Path : domain
Redirect : Permanent 301

But no luck ! im still getting the same cms page (No redirection ) tried clearing cache but still the same result.

3

Magento, rewrite manage work whenever Request Path & Target without base url.

Why, you did tried with htaccess 301 redirection.

It is every good idea use htaccess 301 if you using Apache as web server

# Permanent URL redirect - generated by 
Redirect 301 http://domain.com/home http://domain.com/

Or,you can use magento event observer.

In magento,when a Cms is call,then an event cms_page_render is fire before render layout.

And on this event using magento 301 redirection

(Mage::app()->getResponse()->setRedirect(Mage::getUrl(),301)->sendResponse())

and on basic of page identifier match $observer->getEvent()->getPage()->getIdentifier()=='home'

You can redirect to domain.com/home page to domain.com/

config.xml:

<?xml version="1.0"?>
<config>
......
  <global>
    <events>
      <cms_page_render> 
        <observers>
          <slash_home_to_domain>
            <type>singleton</type>
            <class>ModuleNameSpace_ModuleName_Model_Observer</class>
            <method>Home301redirect</method>
          </slash_home_to_domain>
        </observers>
      </cms_page_render>     
    </events>
  </global>
.....
</config>

Observer code:

<?php
class ModuleNameSpace_ModuleName_Model_Observer
{

    public function Home301redirect($observer)
    {
      $cmspage = $observer->getEvent();
      /* Condition match and redirect to home */
      if($cmspage->getIdentifier()=='home'):
  Mage::app()->getResponse()
      ->setRedirect(Mage::getUrl(), 301)
      ->sendResponse();
      exit();
      endif;
      return;
    }
}
  • I tried redirection with .htacces, But its not working, Iam not an expert in doing these stuff like observer :(. But why the redirection is not working as i mentioned !!! – Shan Nov 29 '15 at 13:58
  • May ur server htaccess now allow magento htaccess – Amit Bera Nov 29 '15 at 14:09
0

Request Path :domain/home
Target Path : domain

I think the issue come from "domain" (other Magento rewrite URLs doesn't mention it)

Try with this:

Request Path: home  
Target Path: /

Let us know if it works,

  • I tried this . But not Redirecting – Shan Nov 29 '15 at 14:19
0

I also had a similar issue. However it worked when I used this combination:

Request Path: home
Target Path: ../

The key points to the above are that the Request Path should not have a preceding forward slash, and the Target Path needs the preceding two dots. This is the only combination that worked on my site.

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.