Redirect keystone app to sub directory using htaccess

779 views Asked by At

I am new in htaccess. I am using Keystone.js, using which I developed a blog which is listening on port 3000. Like this:

https://localhost:3000

Everything is fine now. But what I want is that my blog should run on this url :

https://localhost/blog

How can I achieve this scenario where I provide "https://localhost/blog" and its should work like "https://localhost:3000". In this case URL will remain the same: https://localhost/blog

Plus I also want that when a user visits this url: "https://localhost:3000", it should redirect to: "https://localhost/blog".

How can I achieve this scenario? All I want is to hide a port from URL.

I have tried alot of things to work around but its not working for me. Something like this:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^blog(.*) http://localhost:3000/$1 [P,L]

Ok now this about code is working perfect for main page i.e: https://localhost/blog because I added a rule for it in htaccess. But the issue is that all links, images & included files are broken in my blog.

Now I used base tag for this issue. But it converts my links to this format:

http://localhost:3000/contact
http://localhost:3000/help
http://localhost:3000/post

I considered http://localhost:3000/ as a base tag in my page head. As you can see 3000 port is again appearing in urls which I dont want to show. It should be:

http://localhost/blog/contact
http://localhost/blog/help
http://localhost/blog/post
2

There are 2 answers

0
Kyle Anderson On

This is the safest and easiest way to run Node on port 80:

Login to the server and issue the following commands:

$ sudo apt-get install libcap2-bin
$ sudo setcap cap_net_bind_service=+ep /usr/local/bin/node

Note: Change the path to Node above to whatever is displayed when you type which node

Now when you tell Node to run on port 80, it won't complain. And you won't have to deal with Apache or Nginx, run your app as root, or worry about port forwarding.

0
rebe100x On

I would advise to use NGINX to solve this issue. You can check those links :

https://allaboutghost.com/how-to-proxy-port-80-to-2368-for-ghost-with-nginx/

Node.js + Nginx - What now?