How To Rewrite Nginx For Multi-Language SEO URLs For Magento

How To Rewrite Nginx For Multi-Language SEO URLs For Magento

September 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How To Rewrite Nginx For Multi-Language SEO URLs For Magento

Rewriting Nginx for Multi-Language SEO URLs in Magento

You’re on the right track with your Magento setup on Nginx with fastcgi. However, removing index.php from the URLs to improve SEO requires some configuration tweaks. Here’s a step-by-step guide to help you achieve this.

1. Enable Web Server Rewrites in Magento Administration

First, ensure that “Use Web Server Rewrites” is set to “Yes” in your Magento administration under System > Configuration > General > Web. This enables the .htaccess file and allows for URL rewriting.

2. Check Your Base URLs in Magento Administration

Ensure that your Base URLs are configured correctly. In System > Configuration > General > Web, you should see:

  • Base URL: https://www.examplesite.com/
  • Secure Base URL: https://www.examplesite.com/

The language-specific subdirectories (like /es/) should not be included here.

3. Update Your index.php Files

You’ve already created copies of the index.php file in your language-specific directories, which is great. Here’s how it should look:

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

Mage::run('es');

4. Update Your Nginx Configuration

In your Nginx configuration file, you need to adjust the location block that handles PHP files. Here’s an updated version:

location ~ .php$ {
    if (!-e $request_filename) {
        rewrite / /index.php last;
    }
    expires off;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param HTTPS $fastcgi_https;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param MAGE_RUN_CODE es;  # Update the code here
    fastcgi_param MAGE_RUN_TYPE store;
    include fastcgi_params;
}

Note that I’ve updated es to match your language code. This tells Magento which store to use.

5. Test Your Setup

After making these changes, restart your Nginx server and test the URLs:

  • Spanish: https://www.examplesite.com/es/category.html
  • English: https://www.examplesite.com/category.html

If everything is set up correctly, you should now have clean URLs without index.php.

Conclusion

Removing index.php from Magento URLs on Nginx requires careful configuration of both the Magento administration and your Nginx server block. Ensuring that “Use Web Server Rewrites” is enabled in Magento, updating your base URLs, and adjusting the index.php files and Nginx location blocks are key steps.

Remember to test each URL after making changes to ensure they work as expected. If you encounter any issues, double-check your configurations for discrepancies or syntax errors.

For more detailed guides on Magento configuration, check out Laravel Company’s Magento tutorials.

Admin Configuration SEO

Our network