我正在尝试运行一个简单的Web服务以获取XML客户列表,但是当获取http://www.myshopurl.com/api/customers时,PS重定向到正面页面。
mod_rewrite在apache中打开(使用phpinfo函数检查(。认为.htaccess的形成很好:
# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums
<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#Domain: www.mydomain.com
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api$ api/ [L]
RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+).(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
</IfModule>
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/x-font-woff .woff
<IfModule mod_headers.c>
<FilesMatch ".(ttf|ttc|otf|eot|woff|svg)$">
Header add Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404
# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
IM使用Prestashop 1.6.0.14和PHP版本5.5.9-1ubuntu4.19。添加了新的Web服务并激活。
其他方式,我已经配置了我的000-default.conf apache文件:
<VirtualHost 127.0.0.1:8080>
DocumentRoot /opt/prestashop_folder/
ServerName mydomain.com
ServerAlias www.mydomain.com
<Directory /opt/prestashop_folder>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
不知道您是否需要更多数据。感谢您的时间。
好吧,对不起,帅哥,发现的问题。
服务器具有同时工作的Nginx和Apache。我虽然那个Apache正在与Prestashop的战线合作,但我错了。nginx是。
nginx config的规则将所有URL重定向到index.php。我添加了新规则到/api/*,并且解决了问题。
prestashop nginx配置
rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
https://gist.github.com/julienbourdeau/79961e9caa4263e9e9e34d2d2056948d335