We have searched and searched, but cannot for the life of us figure out how to edit our .htaccess
file to allow our node.js application to run.
www.website.com/api
. node
successfully installed on our centOS6. We are also able to run the node server successfully in the terminal by navigating to the /api
folder and running nohup node my_app.js &
. The logs confirm the server is running on port 51900. Here's the problem. We know the node API is running, we just cant figure out how to see it. We're pretty sure we have to change our .htaccess
file to redirect the /api/
directory. Here is a copy/paste of our .htaccess
file and what we have so far. Our redirects don't seem to work though.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^/api$ http://127.0.0.1:51900/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/api/(.*)$ http://127.0.0.1:51900/$1 [P,L]
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any help is greatly appreciated.
You need to exclude your API URL from wordpress. Also in .htaccess you do not prepend a /
in the rewriterule eg ^/api
. There is no prepending slash in directory (htaccess) context. It should be ^api
. So that's also why your rule is not matching. Try this and see if it helps.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^api/(.*)?$ http://127.0.0.1:51900/$1 [P,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.