Sorry if the title is confusing.
I have set up a virtual host on my local machine. I’ve set http://dev to map to my /htdocs/dev folder. With some help from dnsmasq and .htaccess, I’ve set it up so that it maps subdomains of .dev to folders inside /htdocs/dev. And it all works perfect when I try to access, for example, http://dev/file1.html or http://folder.dev/file2.html. The problem occurs with accessing subfolders. I get a 404 Object not found if I try to access http://folder.dev/subfolder/ or http://folder.dev/subfolder/file3.html.
I guess it can be solved with .htaccess, but I failed to do it although I tried. Here’s how my /htdocs/dev/.htaccess looks like:
# Default index file
DirectoryIndex index.php
# Interpret .html files as .php scripts
AddHandler php5-script .php .html
# Redirect subdomains to their respective folders
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.dev$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.dev$ [NC]
RewriteRule !^([a-z0-9-]+)($|/) /%2%{REQUEST_URI} [PT,L]
I should mention that, if I try to access http://dev/folder/subfolder/file3.html, there are no problems.
How can I set addresses such as http://folder.dev/subfolder/ point to /htdocs/dev/folder/subfolder?
First, thanks goes to @JonLin for giving me a hint about this.
I’ve managed to solve this with this .htaccess file:
What Rewrite part of this does is it takes a URL in form of http://folder.dev/subfolder and points it to /dev/folder/subfolder while preserving the URL. It works with or without www.