Reputation: 1987
I'm using a shared hosting service that always has Apache web server running, so I can't run my Node.js application directly on port 80. Instead, as I've been told by my host, I need to use .htaccess
to redirect incoming requests to my Node.js app, which is currently running on port 50000. Here's the .htaccess
file they told me to use:
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:50000 [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:50000/$1 [P,L]
This works well enough, except that when I try to go to mydomain.com
, the Node app is seeing a request for /index.php
. The tech support for my host seems to be as confused as I am. If I go to mydomain.com/test
then Node.js app sees /test
, so Apache seems to only be adding index.php
on the root URL. Could this be an Apache caching issue from someone accessing the URL prior to the .htaccess
file and Node.js app being set up?
UPDATE
At this point, no one seems to have a clue what is going on, so I'm just going to add an 'index.php' route to my Node app. Thanks to everyone who took a look and tried to help out.
Upvotes: 1
Views: 4033
Reputation: 75
This is actually what you are going to want to put in your /public_html directory
In the .htaccess file in the code below you will see
http://127.0.0.1:50000
(50000) is the port you are sending it too. There are 2 spots where you make that update.
Also update the example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
DirectoryIndex disabled
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:50000 / [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:50000 /$1 [P,L]
This is a specific configuration for an apache server with nodejs.
Upvotes: 1
Reputation: 7476
You might have DirectoryIndex
set up for index.php
in apache conf
file which may be the reason you are getting index.php
automatically, what you can do is to set DirectoryIndex
to some filename which may not exist or if it is apache 2.4 use DirectoryIndex disabled
in your .htaccess
.
Upvotes: 3