Magento: How to remove index.php from admin URL

As you may already know, the index.php from the URLs can be easily removed from the frontend, by going to System -> Configuration -> Web -> Search Engine Optimization and setting Use Web Server Rewrites to Yes. But this works only for the frontend. This can be tricked easily, by overriding one of the Magento core files. Lets see the method which is responsible for the URL generation in Mage_Core_Model_Store:

protected function _updatePathUseRewrites($url)
{
    if ($this->isAdmin() || !$this->getConfig(self::XML_PATH_USE_REWRITES) || !Mage::isInstalled()) {
        $indexFileName = $this->_isCustomEntryPoint() ? 'index.php' : basename($_SERVER['SCRIPT_FILENAME']);
        $url .= $indexFileName . '/';
    }
    return $url;
}

As you can see, when the $this->isAdmin() is true, then it will add the index.php to the URL. So, in order to remove it, we have to:

1. copy app/code/core/Mage/Core/Model/Store.php to app/code/local/Mage/Core/Model/Store.php
2. modify app/code/local/Mage/Core/Model/Store.php file so it will look like:

protected function _updatePathUseRewrites($url)
{
    if (!$this->getConfig(self::XML_PATH_USE_REWRITES) || !Mage::isInstalled()) {
        $indexFileName = $this->_isCustomEntryPoint() ? 'index.php' : basename($_SERVER['SCRIPT_FILENAME']);
        $url .= $indexFileName . '/';
    }
    return $url;
}

Now the only thing you need to do is to go to System -> Configuration -> Web -> Search Engine Optimization and to set Use Web Server Rewrites to Yes, then to clear your cache. This will remove the index.php both from frontend and backend.

Note that overriding core functionality must be avoided as much as possible.

12 thoughts on “Magento: How to remove index.php from admin URL”

  1. Just to know. i had only this folders app/code/local/Mage/ but now i have added Core/Model/ and then pasted store.php. is it right way? or i was looking wrong location ?

    1. Filenames are case sensitive especially under linux OS-es, so make sure that it is Store.php. Your overridden file should be placed into this folder: app/code/local/Mage/Core/Model. Make sure that you edit Store.php as it is written in the article. About reindexing: log in to the backend, go to system -> index management, and there you can reindex, but if the file with the good name is in the right place, then it should work. Maybe if you have Magento compiler, that should be rerun / disabled. Maybe it will be needed also to log out and log in again before any results.

  2. still it is not working. cleaned the cache. did what you said. I am not sure whether Store.php is being read from the local location or from some where else.

    Thanks

    1. Maybe you can modify the app/code/core/Mage/Core/Model/Store.php file directly, and re-compile magento (system -> tools -> compilation). After that, clean up the cache and re-index. I’ve tested this against magento 1.9.3.1, and works fine. Good luck.

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.