Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect keystone app to sub directory using htaccess

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
like image 405
Irtiza shahid Avatar asked Jun 09 '15 13:06

Irtiza shahid


2 Answers

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.

like image 189
Kyle Anderson Avatar answered Oct 12 '22 01:10

Kyle Anderson


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?

like image 23
rebe100x Avatar answered Oct 12 '22 00:10

rebe100x