You're not going to get out of this without a little debugging. The following applies to Magento CE, but should be relevant for Magento EE. Also, this post summarizes a lot of material found in my Magento Dispatch series. If you want to really engage in some bottom up debugging, start there.
To start, most of the Magento problems I see boil down to "I was really sure this one thing was X, but it was actually Y". Even if you're absolutely sure about something I tell you to check, make sure you actually check it.
The routing for Magento's homepage is handled by the Mage_Core_Controller_Varien_Router_Standard
object. The first key part is this line
#File: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
$p = explode('/', $this->_getDefaultPath());
The _getDefaultPath
method looks at your Magento store config for the set value.
protected function _getDefaultPath()
{
return Mage::getStoreConfig('web/default/front');
}
which is the configuration that corresponds to
System -> Configuration -> Web -> Default Pages -> Default Web URL
Tripple check that this value is set to the string
`cms`
and that your core_config_data
table
select * from core_config_data where path = 'web/default/front';
doesn't contain any unexpected scoped values.
Once you've done the above, add some temporary debugging code to peek at the value of $p
after that call.
$p = explode('/', $this->_getDefaultPath());
var_dump($p);
//or
Mage::Log($p);
//or
file_put_contents('/tmp/test.log',"$p\n",FILE_APPEND);
You should see output something like this
array (size=1)
0 => string '' (length=0)
array (size=1)
0 => string 'cms' (length=3)
The reason you have two items being dumped/logged is the match
method is shared between the admin router and the standard router object. If the second item isn't a one element array with cms
, that's your problem. Figure out what that's not happening, and you'll be on your way to solving the problem.
Assuming that's not the problem, Magento should now dispatch to the indexAction
method in the IndexController.php
file in the Mage_Cms
module. Ensure this is the case by adding the following two lines to the start of indexAction
#File: app/code/core/Mage/Cms/controllers/IndexController.php
public function indexAction($coreRoute = null)
{
$pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE);
if (!Mage::helper('cms/page')->renderPage($this, $pageId)) {
$this->_forward('defaultIndex');
}
}
You should see Mage_Cms_IndexController::indexAction
dumped to the browser window. If this doesn't happen, then there's something about your system that's preventing standard routing from being used — jump back up into the match
method and figure out why $controller
, $controllerClassName
, $controllerInstance
, and $action
variables don't point to the indexAction
method in the IndexController.php
file in the Mage_Cms
module. (If this is the case, say so in the comments and I'll provide an update debugging scanrio for this)
Assuming you are being routed to this controller file and action correctly, remove the
var_dump(__METHOD__);
exit;
and instead add a new var_dump
$pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE);
var_dump($pageId);
Magento allows you to configure the identifier of the page that should be used as the home page. The Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE
should corresponds with the store config path web/default/cms_home_page
, which corresponds with the
System -> Configuration -> Web -> Default Pages -> CMS Home Page
section. This is where you tell Magento which CMS page you want to use as your homepage. You should see something like
string 'home' (length=4)
or
string 'about-magento-demo-store' (length=4)
or etc. dumped to your screen. This is the CMS home page identifier. If you're setting an unexpected value, try running the following
select * from core_config_data where path = 'web/default/cms_home_page';
to check for scoped values. Regardless of what you CMS Home Page ID is, check for the page's existence with the following SQL statement (assuming a value of home
).
select * from cms_page where identifier = 'home';
If Magento can't find the configured page in your system, it will forward to the 404 page. You can see that with the following code in indexAction
if (!Mage::helper('cms/page')->renderPage($this, $pageId)) {
$this->_forward('defaultIndex');
}
If renderPage
returns false
, then we're forwarded to the defaultIndexAction
method which renders the 404 page.
public function defaultIndexAction()
{
$this->getResponse()->setHeader('HTTP/1.1','404 Not Found');
$this->getResponse()->setHeader('Status','404 File not found');
$this->loadLayout();
$this->renderLayout();
}
That should be enough to find 90% of your "no route to homepage" problems, and point you in a debugging direction for the other 10%.
Some troubleshooting tips:
Do you have a module registered in app/etc/modules?
If not, it should be as such:
<?xml version="1.0"?>
<config>
<modules>
<ThomasRyan_Checkoutajax>
<active>true</active>
<codePool>local</codePool>
</ThomasRyan_Checkoutajax>
</modules>
</config>
This module naming looks incorrect - it is expected to be separated with an underscore indicating namespace -- so, not this:
<module>Checkoutajax</module>
All modules are named as Company_Module
, etc. Checkoutajax_AjaxController is then not a valid classname. Check your general PHP error log (or Apache logs) and you should see something to the effect of class not exists
.
Change/update this to ThomasRyan_Checkoutajax
or similar. All instances of Checkoutajax will need to be updated in the module xml definition.
The frontName also has issues, namely, it should be lowercase:
<frontName>Checkoutajax</frontName>
I'm not sure if Magento forces the lowercase on the routename.
The updated code, then:
<?xml version="1.0"?>
<config>
<modules>
<ThomasRyan_Checkoutajax>
<version>0.1.0</version>
</ThomasRyan_Checkoutajax>
</modules>
<frontend>
<routers>
<Checkoutajax>
<use>standard</use>
<args>
<module>ThomasRyan_Checkoutajax</module>
<frontName>checkoutajax</frontName>
</args>
</Checkoutajax>
</routers>
<layout>
<updates>
<checkoutajax>
<file>checkoutajax.xml</file>
</checkoutajax>
</updates>
</layout>
</frontend>
</config>
And the controller:
<?php
class ThomasRyan_Checkoutajax_AjaxController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}
}
Edit:
This is just a quick update to explain how routes/controllers/actions work in Magento. Let's say that this is your URL:
www.yourstore.com/checkoutajax/ajax/index
This represents three different entities:
checkoutajax
is the route name, also called frontName
in the module definition XML
ajax
here represents the controller name. This controller file should be named AjaxController.php and located in the /controllers
directory of your module.
index
represents the indexAction
method.
So, to visualize:
www.yourstore.com/checkoutajax/ajax/index
---------route--------^
---------controller-------------^
---------action-----------------------^
Best Answer
You probably want to read Magento's Many 404 Pages. It outlines the various ways Magento can 404 on you, including the page you're talking about.
The short version: The 404 page in the
errors
folder (that'serrors/404.php
, which ultimately includes the404.phtml
file), will render if some piece of Magento code throws aMage_Core_Model_Store_Exception
exception, that exception is uncaught, and Magento isn't running in developer mode.My quick untested way to achieve your goal would be to get your CMS 404 page to throw a
Mage_Core_Model_Store_Exception
.