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
</Directory>
</VirtualHost>
It's 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: example.localhost/test/api/resource
Should become something like: /Applications/MAMP/htdocs/example.localhost/test/api/resource.php
Instead becomes: /Applications/MAMP/htdocs/example.localhost/example.localhost
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.
I am no expert at these configurations and I am largely self taught when it comes to apache so any help would be appreciated.
Thanks