httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Covener <cove...@gmail.com>
Subject Re: [users@httpd] webserver configuration to redirect correctly API calls
Date Tue, 13 Mar 2018 11:55:51 GMT
On Tue, Mar 13, 2018 at 3:51 AM, Anke.Wienecke@gmx.net
<Anke.Wienecke@gmx.net> wrote:
> Hi,
>
> I have to admit that I am a total amateur concerning apache and its configuration. However,
I am in the need to do so. In order to use an API to add data into an application which is
running in apache2 I need to set a redirection.
>
> Everything what I found by now does not really help me, probably also as I do not know
the syntax in detail and which files are really important.
>
> I have the Info how this redirection works in Nginx:
> location ~ ^/api/v1/(.*)/?$ {
> rewrite /api/v1/(.*)$ /app/controllers/ApiController.php?req=$1? last;
> }
>
> In words what the redirection needs to do is that all requests that go to /api/v1/BLAH
are redirected to /app/controllers/APIController.php?=req=BLAH
>
> The "home" directory is: /var/www/html/elabftw
> and the API stuff is in /var/www/html/elabftw/app/controllers/
>
> I tried already something like that:
> - creating a .htaccess file in /var/www/html/elabftw/
> - adding:
> RewriteEngine On
> RewriteRule ^/api/v1/(.*)$ /app/controllers/ApiController.php?req=$1? [R=301]
>
> ..but it does not work...
>
> I would be very happy and thankful for help - in which file (.htaccess??), do I need
to write what...

With mod_rewrite, you need to watch out for a few gotchas (that you
unfortunatley walked right into)


1 - if you have access to the real conf, use it over htaccess. Rules
go in your <virtualhost>.
2 - rules have a slightly different syntax in htaccess -- the leading
prefix of the match is stripped off based on the htaccess location.
Nothing ever starts with /
3 - if you want to capture the query string, you need to add a
RewriteCond then use the %1 backreference.

Probably something close here:
https://wiki.apache.org/httpd/RewriteQueryString


-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message