Redirect index.php to root in .htaccess

Redirect index.php to root in .htaccess

October 19, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Redirect index.php to root in .htaccess

Removing index.php from Magento URLs: A Comprehensive Guide

Are you facing issues with your Magento store where the product URLs contain index.php? You’re not alone—many developers grapple with this common problem on shared hosting environments. In this post, we’ll guide you through the process of removing index.php from your Magento URLs using Apache’s .htaccess file.

Understanding the Problem

By default, when you install Magento, it uses a RewriteRule that appends index.php to all URLs. This is fine for local development or dedicated servers with mod_rewrite enabled. However, on shared hosting where mod_rewrite might not be available, you’ll see both http://mydomain.com/category/product.html and http://mydomain.com/index.php/category/product.html.

Before You Start: Backup Your Files

Before making any changes to your .htaccess file, ensure that you backup all your existing files. This will help you restore them if anything goes wrong during the process.

Step 1: Check Your Current Rewrite Rules

First, open your current .htaccess file located in the root directory of your Magento installation. You should see a block of code that looks like this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]

This rule is responsible for appending index.php to all incoming requests.

Step 2: Modify the Rewrite Rule

Now, let’s modify this rule. We’ll change it so that if a request matches an existing file or directory, it won’t be rewritten to include index.php.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [L]

Notice the subtle change: we’ve removed the $ symbol after index.php. This prevents Magento from appending an extra slash (/) to the URL.

Step 3: Clear Your Cache

After saving your changes, clear the cache in your Magento admin panel. Navigate to “System” > “Cache Management”, select all the caches, and click on “Flush Magento Cache”.

Step 4: Test Your Changes

Now, try accessing a product page that previously included index.php. For example, if you had a URL like http://mydomain.com/index.php/category/product.html, it should now redirect to http://mydomain.com/category/product.html.

If everything works correctly, your Magento installation will no longer append index.php to URLs on your shared hosting server.

Troubleshooting Common Issues

If you’re still seeing the index.php in your URLs after following these steps, check for a few common issues:

  1. Make sure your .htaccess file has the correct permissions. It should have 644 or 666 permissions.

  2. Ensure the RewriteEngine is enabled. Look for RewriteEngine on at the top of your .htaccess file.

  3. Check if a different .htaccess file is being used. Your shared hosting provider might have its own .htaccess file that overrides Magento’s settings.

Conclusion

Removing index.php from your Magento URLs is an essential step to make your store look more professional and improve the user experience. With these steps, you should be able to achieve this on a shared hosting server without needing to access the Apache configuration files directly.

Remember, if you’re still having trouble after following this guide, don’t hesitate to reach out to our team at Laravel Company. We specialize in providing expert Magento support and can help diagnose any issues with your store’s URL structure.

Stay tuned for more tips on optimizing your e-commerce platform!

Catalog API Errors

Our network