我有wordpress 5.4.1和woocommerce 4.2和ssl证书从让我们加密。
在使用查询字符串之前,我设法从API中得到了一个响应。https://www.store.com/wp-json/wc/v3/products?consumer_key=ck_XXXX&consumer_secret=cs_XXX
但突然它停止工作,给我401未经授权的错误。我100%确定密钥的问题。
我使用的是php和FastCgi,我读到有时服务器没有正确读取授权,所以我试了下面的方法。
我补充道
<IfModule mod_setenvif>
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</IfModule>
和
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
到我的.htaccess文件
此外,我还增加了
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
到我的httpd.conf文件中,在RewriteEngine之后,在
我还安装了基本的认证插件 https://github.com/WP-API/Basic-Auth
以上所有的解决方案都未能得到邮递员或失眠症的响应,同样的错误401未经授权。
我终于在2天后得到了答案
最好的解决方案是把上面的东西都去掉,只需加上
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
所以,我的整个htaccess块将看起来像。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>