I have a tiny Express app serving on port 35000 on my web server, and it's accessible from mywebsite.com/api using the following .htaccess code (works perfectly, just sends "hello world" to the browser).
RewriteEngine On
RewriteRule ^api/(.*) http://127.0.0.1:35000/$1 [P]
I have set up a subdomain at api.mywebsite.com linked to a separate directory on my server and if I put web files here I can see them at the URL, so that's working fine. I'd like to move my API to api.mywebsite.com so I've created the following .htaccess file in the directory for the subdomain.
RewriteEngine On
RewriteRule ^(.*) http://127.0.0.1:35000/$1 [P]
But navigating to api.mywebsite.com returns a "Not found" error from Express, with a log of 404 index.php
. Why is an index.php file expected? I'm happy to at least get the error because that means Express is communicating through the subdomain, but it's not giving me my "hello world" message.
I've had a look at Express vhost from other question but am struggling to understand if that's applicable here or if I'm missing a simple .htaccess rule. Any help would be great thank you.
Just to follow up, this solved my question: htaccess proxy to node app
My .htaccess file in my subdomain directory is now:
DirectoryIndex disabled
RewriteEngine On
RewriteRule ^(.*)$ http://127.0.0.1:35000/$1 [P,L]
RewriteRule ^$ http://127.0.0.1:35000/ [P,L]