I am trying to rewrite internally (not redirect) all traffic from api.domain.net
to domain.net/api
.
I've got one VHost handling the domain.net
. This endpoint supports
/api
subdirectory as an entrypoint to API.
I would like to set up another endpoint api.domain.net
, preferably in another VHost which would handle the API traffic. In that case I wouldn't like to use /api
subdirectory, as domain implies that this is an API.
My project is already using .htaccess
to rewrite all the traffic to index.php
, as all requests are routed by PHP. Rule: RewriteRule ^(.*)$ /index.php [L,END]
Ideally I would like to add the new, API rewriting rule to the VHost config, as code (and the .htaccess) shall be the same both for API and non-API clients.
What would be the best way to address this?
I've tried to add a rule (before the index.php
rule) in the .htaccess
just for sake of testing: RewriteRule ^(.*)$ /api/$1
, but for some reason it doesn't do anything.
Once added I was expecting that all traffic e.g.: https://local.domain.net/api_method
would be considered by PHP as originiated from https://local.domain.net/api/api_method
therefore routed properly.
EDIT.
The .htaccess
looks like that (stripped unrelated stuff):
RewriteEngine on
# Allow the Let's Encrypt cert verification
RewriteRule ^.well-known/ - [L,NC]
Options +FollowSymlinks
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^build/js/.*\.js$ - [NC,L]
# Run all non-file-asset requests through site entry point
RewriteCond %{REQUEST_URI} !^/resources/frontend/(images|swf|ttf) [NC]
RewriteRule ^(.*)$ /index.php [L,END]