a MAMP stack problem with regard to document root being applied by mod_rewrite

I am running a MAMP stack and have a somewhat default setup.
I have been trying to avoid having to change any rewrites conditions when taking projects out of MAMP, so I had a look at dynamic mass virtual hosts. From what I read, this would allow me to serve projects out of each respective folder in the MAMP web root as a subdomain of localhost. With this each project would have their own document root.

example.localhost would become Applications/MAMP/htdocs/example.localhost

I got that all setup by enabling virtual hosts in the httpd.conf and then adding the following to the httpd-vhosts.conf.

# Use name-based virtual hosting.
NameVirtualHost *:8888

<VirtualHost *:8888>
    ServerAdmin dev@example.com
    ServerName localhost
    ServerAlias *.localhost
    VirtualDocumentRoot /Applications/MAMP/htdocs/%0

    RewriteLogLevel 3
    RewriteLog "/Applications/MAMP/logs/rewrite.log"

    <Directory "/Applications/MAMP/htdocs">
        Options All
        AllowOverride All
        Order allow,deny
        Allow from all

Its worth mentioning here that I set the default port in the httpd.conf to 8888 to avoid conflicts.

So this all worked fine but when I reach any part of my project that uses a .htaccess file within a directory and a mod_rewrite is triggered, It performs the rewrite and gives me a 404.

With a simple example of adding a .php to the end of a resource with a .htaccess of:
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^([^\.]+)$ $1.php [NC,L]

The url of:

Should become something like:

Instead becomes:

This seems to be a problem with the document root being applied by mod_rewrite but I am not sure how to configure this to make sure the document root is correct. I know that when a .htaccess is applied it assumes use of relative paths but i'm not using any leading slashes or anything like that.

There is an importance here for me not to have to change the .htaccess files within the projects as they will need to continue to work on a standard apache setup.

Thank you
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve BinkCommented:
Can you post a rewrite log excerpt showing one failed request?  The higher the trace level, the better.

I've seen a fair bit of stuff indicating that mod_vhost_alias does not play well with mod_rewrite, but it has mostly been in the context of screwing the pooch on the value of %{DOCUMENT_ROOT}.  One important point I did see is that mod_vhost_alias acts on the same level as mod_alias, meaning *after* mod_rewrite has acted.  That could mean that mod_rewrite is acting properly and being overwritten by the mod_vhost_alias work.

One suggestion I've consistently seen is to try the PassThrough flag.  This should re-submit the newly rewritten URL to the handling process, allowing things to be done "correctly".  I'm still a little fuzzy on how/why this would work in this particular instance, but it has come up too often for me to ignore.
Steve BinkCommented:
Here's some support for my theorizing above:

1) Apache documentation demonstrates an either/or situation in the context of mod_vhost_alias and mod_rewrite.  While it sort of looks like this is done as an academic exercise to show the different methods for achieving dynamic virtual hosting, I find it telling that the two methods are not mixed.  http://httpd.apache.org/docs/2.2/vhosts/mass.html#simple.rewrite

2) mod_rewrite is unaware of alias remapping, which happens after mod_rewrite's work is complete.  http://mail-archives.apache.org/mod_mbox/httpd-bugs/200306.mbox/%3C20030602153151.24218.qmail@nagoya.betaversion.org%3E

3) mod_rewrite uses the %{DOCUMENT_ROOT} value, which maps directly to the DocumentRoot directive, not VirtualDocumentRoot.  https://bz.apache.org/bugzilla/show_bug.cgi?id=26052

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.