Mobile app version of vmapp.org
Login or Join
Phylliss660

: Htaccess redirect for directory listing to virtual host on a local MAMP stack For my local dev environment, I have just upgraded from MAMP to MAMP Pro so that I can easily create virtual hosts

@Phylliss660

Posted in: #Htaccess #Mamp

For my local dev environment, I have just upgraded from MAMP to MAMP Pro so that I can easily create virtual hosts without getting too involved with configuration files. Server names will be formatted as: foldername.localhost

For my site's directory I want to create an htaccess rule to redirect from localhost/foldername to foldername.localhost, where "foldername" is a wildcard.

Is this possible?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Phylliss660

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

Yes, this is possible:

RewriteEngine On
RewriteCond %{HTTP_HOST} =localhost
RewriteCond %{DOCUMENT_ROOT}/ -d
RewriteRule ^([^/]+)(.*) .localhost [R=301,L]


This will redirect localhost/foldername/path/to/file to foldername.localhost/path/to/file (where /path/to/file is optional).

There are two parenthesised sub patterns for the "foldername" () and "URL path" ().

The second RewriteCond directive checks to see whether the first part of the URL is a valid directory.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme