【发布时间】:2012-09-14 13:44:46
【问题描述】:
对不起,如果标题令人困惑。
我在本地机器上设置了一个虚拟主机。我已将 http://dev 设置为映射到我的 /htdocs/dev 文件夹。在 dnsmasq 和 .htaccess 的帮助下,我进行了设置,以便将 .dev 的子域映射到 /htdocs/dev 内的文件夹。当我尝试访问例如http://dev/file1.html 或http://folder.dev/file2.html 时,这一切都很完美。访问子文件夹时会出现问题。如果我尝试访问http://folder.dev/subfolder/ 或http://folder.dev/subfolder/file3.html,我会得到404 Object not found。
我想它可以用 .htaccess 来解决,但我试过了,但还是失败了。这是我的/htdocs/dev/.htaccess 的样子:
# 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]
我应该提一下,如果我尝试访问http://dev/folder/subfolder/file3.html,没有问题。
如何设置http://folder.dev/subfolder/等地址指向/htdocs/dev/folder/subfolder?
【问题讨论】:
标签: .htaccess subdomain directory virtualhost subdirectory