Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento 1.7 REST API nginx rewrite rule. api.php no executed

all If I open the link http://example.com/api/rest/products, it just downloaded api.php, and not the script is executed.

what can it be?

there is my nginx rules for magento site

location /api {
  rewrite ^/api/rest /api.php?type=rest break;
}
location / {
    index index.html index.php;
    try_files $uri $uri/ @handler;
    expires 30d;
}

location ~ (/(app/|includes/|lib/|/pkginfo/|var/|report/config.xml)|/\.svn/|/.hta.+) {
             deny all;
}

  location ^~ /(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
  location /var/export/ { internal; }
  location /. { return 404; }
  location @handler { rewrite / /index.php; }
  location ~* .php/ { rewrite ^(.*.php)/ $1 last; }
  location ~* .php$ {
    if (!-e $request_filename) { rewrite / /index.php last; }
    expires off;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param MAGE_RUN_CODE default;
    fastcgi_param MAGE_RUN_TYPE store;
    include fastcgi_params;
  }
like image 502
Kamik Avatar asked Dec 09 '25 23:12

Kamik


1 Answers

I saw that post, too, and got the same thing.
I changed the rule from break to last and things seem to work now:

location /api {
  rewrite ^/api/rest /api.php?type=rest last;
}

I believe it works this way because last re-scans the rewrites and can execute your '.php' location directive, where break only considers the current location block (/api). Source: http://wiki.nginx.org/HttpRewriteModule#rewrite

like image 187
Morgon Avatar answered Dec 11 '25 14:12

Morgon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!