Answer the question
In order to leave comments, you need to log in
How to connect the Magento module I created so that it reacts to events?
I created a module in Magento, connected it in the admin panel, but I can’t use it on the site in any way. When going to the main page of the site/index.php should make a 301 redirect to the main page without index.php.
Here is the module files code:
app/local/Mymodule/SEO/etc/config.xml
<?xml version="1.0" ?>
<config>
<global>
<modules>
<Mymodule_SEO>
<version>0.0.1</version>
</Mymodule_SEO>
</modules>
<models>
<SEO>
<class>Mymodule_SEO_Model</class>
</SEO>
</models>
<events>
<controller_action_layout_generate_blocks_before>
<observers>
<SEO>
<type>singleton</type>
<class>SEO/Observer</class>
<method>redirect</method>
</SEO>
</observers>
</controller_action_layout_generate_blocks_before>
</events>
</global>
</config>
class Mymodule_SEO_Model_Observer
{
public function redirect($observer) {
if($_SERVER['REQUEST_URI'] == "/index.php") {
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".Mage::getBaseUrl('web'));
exit();
}
}
<?xml version="1.0"?>
<config>
<modules>
<Mymodule_SEO>
<active>true</active>
<codePool>local</codePool>
</Mymodule_SEO>
</modules>
</config>
<?php
require_once 'app/Mage.php';
Mage::app();
$Net=Mage::getModel("SEO/observer");
$Net->redirect();
Answer the question
In order to leave comments, you need to log in
Your task is solved through .htaccess if you have Apache or through location{} in the config if you have Nginx + enabled rewrite in Magento.
if you don't need "index.php" in the url, then you can disable it in System/Configuration/General/Web/Search Engines Optimization/Use Web Server Rewrites: Yes
or you can go to Catalog/URL Rewrite Management / add url rewrite / Create URL Rewrite: custom / Redirect: Permanentl (301)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question