You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by An...@gmx.net, An...@gmx.net on 2018/03/13 07:51:32 UTC

[users@httpd] webserver configuration to redirect correctly API calls

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...

Best,
Anke

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


Re: [users@httpd] webserver configuration to redirect correctly API calls

Posted by Anke Wienecke <An...@gmx.net>.
It is not my API. But I will forward your comment to the developper! Thanks!

Also thanks to Eric! I will go through "RewriteQueryString".

On 2018/03/13 12:31:23, Frank Gingras <th...@apache.org> wrote: 
> Why is your API not using pathinfo? You could simply use FallbackResource
> /app/controllers/ApiController.php then.
> 
> On Tue, Mar 13, 2018 at 7:55 AM, Eric Covener <co...@gmail.com> wrote:
> 
> > On Tue, Mar 13, 2018 at 3:51 AM, Anke.Wienecke@gmx.net
> > <An...@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
> >
> >
> 

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


Re: [users@httpd] webserver configuration to redirect correctly API calls

Posted by Frank Gingras <th...@apache.org>.
Why is your API not using pathinfo? You could simply use FallbackResource
/app/controllers/ApiController.php then.

On Tue, Mar 13, 2018 at 7:55 AM, Eric Covener <co...@gmail.com> wrote:

> On Tue, Mar 13, 2018 at 3:51 AM, Anke.Wienecke@gmx.net
> <An...@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
>
>

Re: [users@httpd] webserver configuration to redirect correctly API calls

Posted by Eric Covener <co...@gmail.com>.
On Tue, Mar 13, 2018 at 3:51 AM, Anke.Wienecke@gmx.net
<An...@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