I am having this issue with an external platform which trying to get rest urls from my magento 2.4.5.

Issue is that the urls they hit contain


inside. They are like this:


As you see inside the url is included


I use nginx as web server and although I have this rule:

try_files $uri $uri/ /index.php$is_args$args;

which should strip index.php from url, for some reason in rest urls it doesn't work

And this gives 404 Not found

So I am trying to remove the index.php from rest urls

I inserted this additional rule in nginx:

location /api/ {
  rewrite ^index.php/rest/(.*)$ https://%example.com/rest/$1;

But no luck.

Any help please?

  • How your other API works? May 24, 2023 at 11:47
  • @DhirenVasoya they work just fine...Issue is only happening with Klaviyo
    – G. G.
    May 25, 2023 at 18:40

1 Answer 1


Try this following steps it will be useful to you

Remove the "index.php" from the REST URLs in Magento 2.4.5 when using nginx as your web server, you can modify your nginx configuration with the following changes.

1.Open your nginx configuration file for your Magento site. This file is typically located at /etc/nginx/sites-available/your-site.conf or /etc/nginx/conf.d/your-site.conf.

2.Within the server block, locate the location / section. This section handles the requests for your Magento site.

3.Add the following rewrite rule within the location / section:

location / {
    rewrite ^/(index\.php/)(.*)$ /$2 last;

4.Save the nginx configuration file and exit.

5.Restart or reload nginx for the changes to take effect. Use the command sudo service nginx restart or sudo systemctl reload nginx'.

The added rewrite rule will remove "index.php" from the URLs before processing

After implementing these changes, test your REST URLs again to see if the "index.php" is successfully removed and the 404 error is resolved.

Note: Make sure to replace your-site.conf with the actual configuration file name for your Magento site, and %example.com with your actual domain name in the nginx rewrite rule.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.