Jason
Jason

Reputation: 13956

Apache HTTPD: Proxy url pattern to another server

I'm using an apache HTTPD server as a front, and want to redirect certain urls to another server running locally.

For instance I want:

http://www.example.com/index.php to load the file located at /var/www/index.php http://www.example.com/products/*proxied to another local server & url, e.g. http://127.0.0.1:9000/

I'm trying to write a simple .htaccess file in the root www directory, but whenever I do this simple example, it gives me a File does not exist error in the httpd log:

.htaccess:

RewriteEngine On
RewriteRule ^test.html$ /index.php

I tried to lookup this error, but all the references online are out of date. For instance, mod_rewrite error: [client 127.0.0.1] File does not exist references httpd.conf which is no longer included with apache httpd.

Does anyone know why mod_rewrite isn't working? or how to write a redirect to another local server?

Upvotes: 2

Views: 1970

Answers (1)

Jon Lin
Jon Lin

Reputation: 143856

To reverse proxy, you need to use the P flag:

RewriteRule ^/?products/(.*)$ http://127.0.0.1:9000/$1 [L,P]

You need to have mod_proxy loaded for this to work, otherwise it'll redirect the browser instead.

Upvotes: 1

Related Questions