Jaquarh
Jaquarh

Reputation: 6693

PHP - .htaccess Re-Write for external server connections

I have multiple servers and a main server hosting my API.

[Server 1] <---> [API Server]
[Server 2] <---> [API Server]

I am having a bit of struggle actually sending the curl request to the API server and am unsure if its possible from external servers. I read up an article about using a redirect so the server acts like its internal (CORS).

The URL needed is (where the API file is located):

$this->url = "http://www.example.com/API/RequestsDJ/API/RequestsHandler.php";

However, I am struggling with writing the .htaccess file, so far I have:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule API/RequestsDJ/(.*)$ API/RequestsDJ/API/RequestsHandler.php [QSA,NC,L]
</IfModule>

The idea here is to convert the URL to:

$this->url = "http://www.example.com/API/RequestsDJ";

Which is then, through the CORS method, redirected as an internal request which then runs the functions inside the: API/RequestsDJ/API/RequestsHandler.php file. (I am not sure also if this will carry the POST data with it but for now, its just for testing).

Could anyone give me a hand? Thanks in advance, I suck at .htaccess files (the API doesn't support any GET requests, so any ?example= is not needed).

Upvotes: 3

Views: 88

Answers (1)

jylipaa
jylipaa

Reputation: 111

I think you have to change the rexep rule on RewriteRule from this:

RewriteRule API/RequestsDJ/(.*)$ API/RequestsDJ/API/RequestsHandler.php [QSA,NC,L]

To this:

 RewriteRule ^API/RequestsDJ/(.*)$ API/RequestsDJ/API/RequestsHandler.php [QSA,NC,L]

You probably don't need the QSA flag either as you take all parameters in using POST. Query params won't be required.

Upvotes: 1

Related Questions