Home index.php won't recognize route when fetching from node
Reply: 0

index.php won't recognize route when fetching from node

user2507 Published in June 19, 2018, 6:23 pm

I'm build kind of a proxy in Nodejs for a payment gateway to connect with an application I have in PHP.

I'm trying now to hit an endpoint in my PHP application from my node server with a GET request, but I keep getting the same error "Too Many Redirects".

Searching Google I found out that this is error usually has to do with the rewrite module in my .htaccess file, that might be endlessly redirecting my route, never falling out of the rewrite conditions.

Taking a look at my .htaccess file it seems pretty boilerplate and I don't know what could be causing this infinite redirect loop.

<IfModule mod_rewrite.c>
  RewriteEngine On
  # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
  #  slashes. If your page resides at http://www.example.com/mypage/test1 then use RewriteBase /mypage/test1/
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
<IfModule !mod_rewrite.c>
  # If we don't have mod_rewrite installed, all 404's can be sent to index.php, and everything works as normal.
  # Submitted by: ElliotHaughin
  ErrorDocument 404 /index.php

The weirdest of all is if I try exactly the same route using Postman or the browser everything works fine! The controller is hit and I get my response.

Also, on further research, I manage to log the request object in my index.php file for a working request from Postman and the failing one from my nodejs server. They seem pretty much the same in almost all fields, except in the fields describing the URLs. In the success request I get the following fields:

   // this is logged once
   [REDIRECT_QUERY_STRING] => /notifica
   [REDIRECT_URL] => /notifica
   [QUERY_STRING] => /notifica
   [REQUEST_URI] => /notifica

But when fetching from nodejs these are the fields I get:

   // this is logged many times until I reach my redirect limit
   // [REDIRECT_QUERY_STRING] doesn't exist
   // [REDIRECT_URL] doesn't exist
   [REQUEST_URI] => /

Does anyone know what could be causing this behavior? Why would a request work from Postman and the browser but not from an application in Nodejs? Maybe I'm missing something in the headers the two programs add by default but the modules I use to make the requests don't?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301502 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO