I have created a controller for my custom module. My controller path is like http://www.example.com/test/index/index which is displaying page correctly. I want to perform URL-rewrite for converting /test/index/index
to /test.html
Based on the first answer, I have modified my code as below:
I tried to do something like following, in my config.xml
<frontend>
<routers>
<test>
<use>standard</use>
<args>
<modules>
<module>Pfay_Test</module>
<frontName>test</frontName>
</modules>
</args>
</test>
</routers>
</frontend>
<global>
<controller_front_init_routers>
<observers>
<test> <!-- observer identifier -->
<class>Pfay_Test_Controller_Router</class>
<method>initControllerRouters</method>
</test>
</observers>
</controller_front_init_routers>
</global>
In /app/code/local/Pfay/Test/Controller/Router.php
<?php
class Pfay_Test_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract{
/**
* Initialize Controller Router
*
* @param Varien_Event_Observer $observer
*/
public function initControllerRouters($observer){
$front=$observer->getEvent()->getFront();
$front->addRouter('test',$this);
}
/* validate and modify the request
* Params Zend_Controller_Request_Htt
*/
public function match(Zend_Controller_Request_Http $request){
/* If Magento Magento is not install then
* redirect to installer url
*/
If(!Mage::isInstalled()):
Mage::app()->getFrontController()->getResponse()
->setRedirect(Mage::getUrl('install'))
->sendResponse();
exit;
endif;
$requestPathInfo=trim($request->getPathInfo(),'/');
Mage::log('aaa'.$requestPathInfo.'StoreId'.Mage::app()->getStore()->getId(), null, 'logfile.log');
/* check -review-form not exit
* then immediate return false
*/
if($requestPathInfo!='test.html'):
return false;
endif;
$request->setModuleName('test')
->setControllerName('index')
->setActionName('index');
$request->setAlias(
Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS,
'test.html'
);
return true;
}
}
In /app/code/local/Pfay/Test/Model/Observer.php
<?php
class Pfay_Test_Model_Observer{
public function add($observer){
$identifier=$observer->getEvent()->getCondition();
Mage::log('aaa', null, 'logfile.log');
}
}
But when I type http://www.example.com/test.html , it is still showing 404 error
.Can anybody hint out where it is going wrong?
I am using Magento 1.9
, Apache 2.4
and mod_rewrite
is enabled.