2

I'm trying to host my front-end on some shared hosting solution, but face some issues with that.
Note: This is not supposed to be the definitive hosting solution, but I'd be able to manually test things more accuratetly that way.

My front-end needs to access some API located on a different server. For convenience (authentication and the likes), I'd like to proxy my API requests to the back-end server.
However, being in a shared hosting environment restricts my options :

  • I cannot modify the VirtualHost configuration
  • mod_proxy seems to be disabled, so no ProxyPass or ProxyPassReverse allowed
  • mod_rewrite seems to be enabled

I thought about using
RewriteRule ^/api/(.*)$ https://example.com/$1
as a proxy of sorts, but I'm afraid this will not work as intended...

I'm open to any suggestions and "Do not do this!"

2

You can't create a proxy using Apache without mod_proxy. The P flag that can be used with mod_rewrite (on the RewriteRule directive) uses mod_proxy.

RewriteRule ^/api/(.*)$ https://example.com/$1

Presumably, you are limited to .htaccess, in which case the above RewriteRule pattern (with a slash prefix) would never match anyway, so the directive wouldn't do anything. However, even after correcting the pattern, when you specify an absolute URL in the RewriteRule substitution it will implicitly trigger an external 302 redirect (unless the request is sent through mod_proxy) - which I gather is not what you require.

I can only suggest that you perhaps manage this "proxy" with your server-side code instead. For instance, you could potentially use CURL to "proxy" the request?

  • Well, that's what I thought... Thanks for answering anyway :) – Askirkela May 16 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.