3

Let's say I have a virtual host with a ServerName directive like so:

ServerName geekspeak.dev

And in my hosts file:

127.0.1.1 geekspeak.dev

Now when I enter geekspeak.dev in my browser, I'm directed to my application running on localhost. Simple.

But what if instead of geekspeak.dev, I want to require users to enter geekspeak.dev/foo to get to my app. Is there an apache directive or some other technique that will allow me to accomplish this?

Thanks!

Edit

I tried adding an empty DocumentRoot and an Alias as suggested by Shi, but I had no success. I wonder if the fact that it's acting as a proxy has anything to do with it? I've pasted my virtual host below, maybe someone can see what's wrong with it.

<VirtualHost *:80>
  ServerName geekspeak.dev

  DocumentRoot /var/www/foo
  Alias /foo /var/www/foo

  ProxyPreserveHost On
  ProxyPass /excluded !
  ProxyPass / http://127.0.0.1:9000/
  ProxyPassReverse / http://127.0.0.1:9000/
</VirtualHost>

I'm expecting this to reach my app at / but instead it reaches my app at /foo

1
  • do you get any workaround? I also want to do same (hide application context path from end user using apache 2)
    – HybrisHelp
    Jan 15, 2018 at 10:21

1 Answer 1

2

My guess is that you use DocumentRoot inside your virtual host pointing to your application.

For "drop-in" installation of applications I suggest you simply use an empty directory as DocumentRoot, or whatever content should be available there, and use Alias to point to your application.

Alias /foo /var/www/web-application
2
  • I can't get this to work properly. I've updated my question to include the contents of the virtual host. Let me know if anything stands out. Thanks!
    – Samo
    Aug 20, 2012 at 14:57
  • @Samo: Having both DocumentRoot and Alias pointing to the same directory looks VERY strange. /excluded is served from geekspeak.dev, so right now it has to be located in the filesystem at /var/www/foo/excluded. Maybe that's right, maybe not, I do not know. Anyway, you proxy everything, including /foo to 127.0.0.1:9000. Simply ProxyPass /foo ! to not proxy your application.
    – Shi
    Aug 20, 2012 at 20:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .