history 6 of 36
How to Remove index.php from URLs in Magento 1
Turn on web server rewrites, set RewriteBase in .htaccess and clear the cache so Magento 1 URLs no longer contain index.php.
Written
- Magento
- Web servers
- Written for Magento 1
From my Linux study notes, 2012. Some commands and versions here are old, so please reuse them carefully. Anything marked "added later", and the notes at the end, explain what has changed since.
(Added later.) This post is for Magento 1. Magento 1 reached end of life on 30 June 2020 and no longer receives security updates. The steps below do not apply to Magento 2 / Adobe Commerce.
By default, Magento 1 URLs can look like http://example.com/index.php/my-product.html. With a few changes you can remove index.php so they look like http://example.com/my-product.html. Here are the steps.
Before you start
(Added later.)
- Apache must have
mod_rewriteenabled, and the Magento directory must allow.htaccessoverrides (AllowOverride Allin the Apache configuration). If not, the rewritten URLs will return “404 Not Found” errors. - Back up
.htaccessbefore you edit it.
Steps
-
Set Use Web Server Rewrites to Yes. It is in Admin > System > Configuration > Web > Search Engine Optimization.
This tells Magento to generate links without
index.php, and relies on Apache’s rewrite rules to send those requests toindex.phpbehind the scenes. -
Change to Yes at “Use Web Server Rewrites”. Located in Admin > System > Configuration > Web > Secure / Use Secure URLs in Frontend.
Added note: this step repeats the “Use Web Server Rewrites” wording from step 1 but points to the Secure section, where the setting is Use Secure URLs in Frontend, so it is not completely clear what was meant. “Use Secure URLs in Frontend” makes the shop use HTTPS on pages such as checkout and customer account. Only set it to Yes if your site has a working SSL certificate; it is not required to remove
index.php. -
Edit the
.htaccessfile in your Magento directory:Terminal window vi /yourdir/.htaccessIf you installed Magento in a subfolder, uncomment this line (remove the
#):#RewriteBase /magento/and change it to match your installation folder:
RewriteBase /yourInstallationFolder/For example, if the shop is at
http://example.com/shop/, useRewriteBase /shop/. If Magento is installed in the web root, you can usually leave this line commented. -
Save the Magento configuration and clear the cache. Now you are done.
Added note: you can clear the cache in Admin > System > Cache Management, or by deleting the contents of the
var/cachedirectory inside your Magento folder.
Good luck.
How to check it worked
(Added later.)
Open your shop’s home page and click a category or product. The address bar should not contain index.php. If you get “404 Not Found” errors instead, check that mod_rewrite is loaded and that AllowOverride All is set for the Magento directory, then restart Apache.
Notes for today
- Magento 1 is no longer supported. Running it on a live shop is a security risk, particularly for anything that handles payments. The replacement is Magento 2 (Magento Open Source / Adobe Commerce), which handles web server rewrites differently; follow the documentation for your version.