What is the best way to remove index.php from URLs, without making too many modifications to the Magento core structure and native behavior?


The best way is to do it at an apache or nginx level in the vhost configuration. No need to change Magento codebase for this.

If you use apache, usually this is part of magento .htaccess, check this section:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

If you use nginx, make sure to add this to your vhost configuration:

location / {
    try_files $uri $uri/ /index.php?$query_string;

After changing the nginx vhost file, you need to reload nginx configuration.

  • Is there any danger in doing this? Would there be any situations in which some urls would be inacessible or broken? Thanks! – Supersonic Jul 20 '15 at 13:46
  • Not really, at least I can't think of any good reason. Besides this is the default behaviour. The rewrite is just "hiding" the index.php part in the url. So if properly configured it should be fine – lloiacono Jul 20 '15 at 13:48
  • The Nginx part, is it an "and" or an "or", depending if Nginx is installed? Thanks! – Supersonic Jul 20 '15 at 13:50
  • Yes, it's and "or". If you use apache, then make sure you have your .htaccess in place and that is configured properly. If your are using nginx, then make the changes in the vhost file. One or the other. Not both – lloiacono Jul 20 '15 at 13:53
  • I'm trying with this approach. But, this approach cannot remove like hostname.com/index.php/blahblah.html. It's work in hostname.com/index.php – 502_Geek Oct 28 '16 at 10:40

On apache use the .htaccess, best copy it to your VHost config.

On nginx you need something similiar.

Beside this you need to turn on:

System > Config > General > Web 
    > Search Engines Optimization > Use Web Server Rewrites > YES

Not the answer you're looking for? Browse other questions tagged or ask your own question.