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.
Thank you. Works great. Tested on Magento 1.9.0.1 and 1.9.1.0
Its not working for me. Any thing more needs to be done apart from what you suggested.
I would reindex the site and clean the cache.
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 ?
But still it is not working. cleaned the cache. not sure what do you mean by reindex?
Thanks
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.
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
I’ve sent you a private mail. Send me some credentials of your site and I’ll try to fix it.
In front end it is working with that setting. only it was not working for backend.
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.
Works. Thanks
Thanks, Works like charm.