1

I'm new to Apache and I'm having trouble understanding Rewrite rules.

On my test server I have an arbitrary Apache config which serves up an Elasticsearch instance to select IPs.

What I have so far is:

<VirtualHost *:80>
ServerName home.mytest.server

ProxyPass /esearch http://127.0.0.1:9200
ProxyPassReverse /esearch http://127.0.0.1.9200

<Location /esearch>
    order deny,allow
    deny from all
    allow from <my IP>
</Location>

<Location /esearch/*/_search>
    #Alter URI in here
    order deny,allow
    deny from all
    allow from <my IP>
</Location>

</VirtualHost>

What I want to do is rewrite all requests to /esearch/*/_search to include a default value in the path. So /esearch/*/_search is rewritten to /esearch/myIndex/*/_search.

How do I do this? I've read up about the RewriteConditions and Rules but it's not really sinking in.

1 Answer 1

1

Try something like the following instead of the ProxyPass directive:

RewriteEngine On
RewriteRule ^/esearch/([^/]+)/(_search.*) http://127.0.0.1:9200/myIndex/$1/$2 [P]
RewriteRule ^/esearch/?(.*) http://127.0.0.1:9200/$1 [P]

This uses mod_rewrite in combination with mod_proxy (P flag) to rewrite/proxy the request.

You only need your first <location /esearch> container.

So /esearch/*/_search is rewritten to /esearch/myIndex/*/_search

However, according to your earlier ProxyPass directive, this is proxied to /myIndex/*/_search. Which is what the mod_rewrite directive attempts to do.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .