• I’m using my POS to send my products to woocommerce with the help of the REST API.

    However my server is using FastCGI, and trying to send it over always gave me a 401 error, so I went and read the Getting started with the REST API page and found out I had to change the htaccess file and add this:

    #BEGIN WordPress
     <IfModule mod_rewrite.c>
     #METALOCATOR: This line added to allow basic authentication under FastCGI
     SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
    
     RewriteEngine On
     RewriteBase /
     RewriteRule ^index\.php$ - [L]
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule . /index.php [L]
    
     #METALOCATOR: This line added to allow basic authentication under FastCGI
     #METALOCATOR: Establishes an environment variable used by the plugin only for URLs beginning with wp-json/
     RewriteRule ^wp-json/.* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
     </IfModule>
     #END WordPress

    Then I clicked send on postman and got it working, I could now upload my products to wordpress directly from my POS.

    However my website wasn’t yet forcing https://, as soon as I forced https I got a 500 Error.

    So what I did after was changing the HTTP text in the code above to HTTPS, and that didn’t take my site down, but now I’m back at square one getting a 401 error and not being able to upload my products again.

    What am I doing wrong? If anyone can help me I’ll pay you a coffee or something.
    I’m using Siteground btw.

    • This topic was modified 4 years, 6 months ago by lourencolemos.
Viewing 2 replies - 1 through 2 (of 2 total)
  • @lourencolemos

    Can you update the conf file instead ?

    Did you intend to have the RewriteRule only on the json ?

    RewriteRule ^wp-json/.* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
    to
    RewriteRule ^(.) – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

    Also, you could try this :
    https://github.com/Tmeister/wp-api-jwt-auth

    Thread Starter lourencolemos

    (@lourencolemos)

    Hi Corrina,

    It seems I fixed it by editing the htacess file myself and forcing https myself on all site links by using the search and replace database plugin.

    Here’s the code:

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 
    
    # BEGIN WordPress
    	<IfModule mod_rewrite.c>
    	RewriteEngine On
    	RewriteBase /
    	RewriteRule ^index\.php$ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
    	RewriteCond %{REQUEST_FILENAME} !-f
    	RewriteCond %{REQUEST_FILENAME} !-d
    	RewriteRule . /index.php [L]
    	</IfModule>
    	# END WordPress

    Thanks for your help, very kind.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Please help me figure out this mess, Woocommerce REST API, FastCGI and HTTPS’ is closed to new replies.