3

I've got LAMP setup on a VM that I use for multiple projects. My document root is a /www and I create a folder for each project within it.

/www/project1-name/
/www/project2-name/

I access them in my browser like this:

http://dev.vm/project-name/

I'd like to move my htaccess and index files to a public folder within a project, so they match their production setup more accurately.

/www/project-name/public/

...but still access them with the same url as above. How can I get Apache configured to look for public/ folders as document roots for each of my projects?

Note: I understand I can create hosts and vhost entries for each project to have it's own document root, but I'm trying to to avoid that - because I plan on using a similar setup on my remote server to house multiple projects at a subdomain called 'demo'.

Magellan
  • 4,451
  • 3
  • 30
  • 53
Atticus Finch
  • 41
  • 1
  • 4

3 Answers3

3

I'd go one step further with mod_alias and use the AliasMatch directive. Should work the same as EightbitTony's solution, but give you the extra regex power.

I did a bit of testing and this looks like it should do it.

AliasMatch ^/([a-zA-Z0-9_-]+)/(.*) /www/$1/public/$2
kashani
  • 3,922
  • 19
  • 18
1

I don't think you want to do any re-writing, don't you just want some good old fashioned Alias statements?

From http://httpd.apache.org/docs/2.0/mod/mod_alias.html,

Description: Maps URLs to filesystem locations
Syntax:      Alias URL-path file-path|directory-path
Context:     server config, virtual host
Status:      Base
Module:      mod_alias

So,

Alias /project-name/  /some/path/to/project-name/public/
Alias /project-name2/ /some/path/to/project-name2/public/
Alias /project-3/     /another/totally/different/path/public/
EightBitTony
  • 9,311
  • 1
  • 34
  • 46
  • Is it possible to do it dynamically with some specific conditional logic? So I won't have to add a new vhosts entry for every new project. – Atticus Finch May 28 '12 at 19:11
  • It's not a vhost, it's an alias. You only have to add one line to your apache config per project. I'm sure it is possible to use re-write to do it dynamically, but it's overkill. – EightBitTony May 28 '12 at 19:19
1

Take a look at the apache dynamically configured mass virtual hosting documentation. It doesn't sound like you have huge numbers of vhost so the VirtualDocumentRoot and related configuration directives will probably do what you want e.g.

 VirtualDocumentRoot /www/%2/public

which would map to /www/project-name/public. The %n parameter is interpolated from the URL with %0 being the whole, %1 the first part etc.

user9517
  • 115,471
  • 20
  • 215
  • 297