Remove Index.php from Magento URL in .htaccess

Remove Index.php from Magento URL in .htaccess

August 1, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Remove Index.php from Magento URL in .htaccess

Removing Index.php from Magento URL using .htaccess

As a developer who has worked extensively with Magento, I often receive queries about removing the index.php file from the store’s URL structure. The presence of this file can make your Magento URL look unprofessional and messy.

One common misconception is that adding certain code snippets to your .htaccess file will automatically remove the index.php. However, it’s important to understand how Magento handles rewrites and routing before attempting any changes.

Understanding Magento’s Routing

Magento uses a unique routing system that is different from other e-commerce platforms. When you access a URL in your Magento store, for example mydomain.com/about-us, the request doesn’t directly map to an actual file on your server. Instead, it goes through a series of checks and rewrites.

The core of this system lies in the .htaccess file located at the root level of your Magento installation. This file contains rules that handle URL rewriting, SEO-friendly URLs, and other core functionalities.

The Incorrect Approach

You mentioned finding code online that supposedly removes index.php from the URL. Let’s analyze why this approach doesn’t work:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /

    RewriteRule .* index.php [L]
</IfModule>

The issue with this configuration is that it simply rewrites every request to index.php, regardless of the path. This would break your entire site, as Magento needs to differentiate between different URLs for routing purposes.

The Correct Approach: Modifying the Base URL in Magento

Rather than trying to manipulate the .htaccess file directly, you should modify the base URL setting within the Magento admin panel. Here’s how:

  1. Log into your Magento admin panel (usually at mydomain.com/admin).

  2. Navigate to Stores > Configuration > General > Web.

  3. In the Base URLs section, locate the fields for Default Config Scope and Current Configuration Scope.

  4. Click on the scope drop-down menu (it should be set to ‘Default Config’).

  5. Change the URL Prefix field from mydomain.com/index.php/ to just mydomain.com/.

  6. Save the configuration by clicking the ‘Save Config’ button at the top right of the page.

  7. Flush your Magento cache to ensure the changes take effect immediately. You can do this from System > Cache Management, selecting all caches and clicking ‘Flush Magento Cache’.

Verifying the Changes

After following these steps, you should be able to access your site without index.php in the URL. If you navigate to a category or product page (e.g., mydomain.com/category) or use an SEO-friendly URL (like mydomain.com/about-us), the system will correctly route the request without needing the index.php file.

Remember, any changes to your .htaccess file should be done with great caution. Always back up your files before making modifications to avoid potential downtime or data loss.

Conclusion

Removing index.php from a Magento URL is more about configuring the base URL in the admin panel than directly editing the .htaccess file. By setting the correct scope and URL prefix, you can achieve SEO-friendly URLs without needing to touch the rewrite rules.

If you’re looking for more advanced Magento tutorials or need professional development services, feel free to reach out to our team at Laravel Company. We specialize in helping businesses optimize their e-commerce platforms and navigate complex technical challenges.

Extensions Themes Configuration Import/Export

Our network