How to remove index.php from Magento with NginX

How to remove index.php from Magento with NginX

August 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to remove index.php from Magento with NginX

Removing Index.php from Magento URLs with NginX

If you’re using Magento on an NginX server and want to remove “index.php” from your URL structure, the process is straightforward once you understand how rewrites work in Magento’s configuration.

Why Remove index.php?

Removing “index.php” provides a cleaner, more professional look for your URLs. It also makes your site easier to crawl by search engines like Google.

Enabling Apache Mod_Rewrite (for NginX users)

Before we proceed, note that the guide linked in the question is primarily for Apache servers using the mod_rewrite module. While it’s not directly applicable to NginX, we can achieve similar results with proper configuration.

First, make sure you have the mod_rewrite module enabled on your NginX server:

server {
    listen 80;
    index index.php index.html;

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

    location ~ \.php$ {
        fastcgi_pass http://127.0.0.1:9001;
        include fastcgi_params;
    }
}

Enabling Web Server Rewrites in Magento

In your Magento admin panel, navigate to Stores > Configuration > General > Web. Set the following:

  • Use Web Server Rewrites: Yes
  • Rewrite Base: /

Click Save Config and then Flush Cache on the top right corner.

The 404 Error on Store Views

If your secondary store view is not working after enabling rewrites, it’s likely due to the URL key format for that view. Magento uses different URL keys for each view by default.

To resolve this:

  1. Go to Catalog > URL Rewrite Management.
  2. Filter by the secondary store view.
  3. Check if all URLs have the correct format (e.g., /es/your-page.html).
  4. If any are missing or incorrectly formatted, edit them accordingly.

Conclusion

Removing “index.php” from Magento URLs requires a combination of enabling rewrites in your admin panel and ensuring proper configuration on your NginX server. While the official guide mentions Apache’s mod_rewrite, the principles remain similar for NginX with correct server block configuration.

Remember, URL rewrites are a powerful feature but can cause issues if not configured correctly. Always test thoroughly after making changes.

For more advanced Magento configurations like setting up multiple stores or implementing responsive design, consider our Magento Development Services.

Don’t hesitate to reach out if you have any further questions about Magento development or need expert assistance with your project.

Cache Indexing Database Extensions

Our network