我有wordpress 5.4.1和woocommerce 4.2,还有我们加密的ssl证书
在使用查询字符串https://www.store.com/wp-json/wc/v3/products?consumer_key=ck_XXXX&consumer_secret=cs_XXX之前,我设法从API获得了一个响应,但是突然它停止了工作,给了我401未授权的错误。我对钥匙有百分之百的把握。
我在FastCgi中使用php,我读到有时服务器无法正确读取授权,所以我尝试了以下方法
我添加了
<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}]在RewriteEngine on之后添加到我的httpd.conf文件
我还安装了基本的身份验证插件https://github.com/WP-API/Basic-Auth
以上所有解决方案都无法从邮递员或失眠症获得响应,并显示相同的错误401 unauthorized。
发布于 2020-06-04 01:06:35
两天后我终于得到了答案
最好的解决方案是删除上述所有内容,只需添加
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>https://stackoverflow.com/questions/62173852
复制相似问题