Apache dynamic aliases

aliasapache-2.2dynamicvirtualhost

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'.

Best Answer

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
Related Topic