: 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
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?
More posts by @Phylliss660
1 Comments
Sorted by latest first Latest Oldest Best
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.