我无法在带有子目录的url上设置虚拟主机。。。我需要在这样的地址上运行我的项目:
http://www.projects.loc/project1/
这应该模拟在网络服务器上的安装,其中地址将类似
http://www.someServer.com/projects/project1/
我需要将重定向调整为"/",以便返回www.projects.loc/project1/
在hosts.txt中我有:
127.0.0.1 www.projects.loc
vhosts已启用,httpd-vhosts.conf如下所示:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "D:/Projects/Project1/public/"
ServerName www.projects.loc/project1/
</VirtualHost>
我错过了什么?
编辑:.htaccess如下所示:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule !'.(js|ico|gif|jpg|png|css)$ index.php [NC,L]
该应用程序在干净的域上正常运行,但我无法将其配置为在domain.com/some_dir/上运行
编辑:
解决了这个问题!
NameVirtualHost *:80
<Directory "D:/Projects">
allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "D:/Projects"
ServerName www.projects.loc/
Alies /project1 /Project1/public/
</VirtualHost>
注意:这是仅适用于开发环境的最低配置,
有关生产环境的全部详细信息,请查看@M-z中已接受的ansler。
您可能已经解决了这个问题。无论如何,我今天看到了类似的事情,因此我在这里记录了解决方案:
您不希望在ServerName
ServerNamewww.projects.loc/project1/中写入斜线
如果你只有一个名为"project1"的项目,你可以用"ServerPath"轻松完成任务,那么你的vhost配置将如下所示:
<VirtualHost *:80>
ServerName projects.loc
ServerAlias www.projects.loc
ServerPath /project1/
DocumentRoot /PATH/public_html
ErrorLog /PATH/error_log
CustomLog /PATH/access_log combined
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /PATH/public_html>
Options -Indexes +IncludesNOEXEC +FollowSymLinks
allow from all
</Directory>
</VirtualHost>
通过ServerPath,您可以将目录装载到项目。loc/project1
无论如何,假设您有几个项目(project1、project2)要绑定到projects.loc.project1、projects.loc.project2等,请使用"Alias"。你的vhost配置文件应该是这样的:
<VirtualHost *:80>
ServerName projects.loc
ServerAlias www.projects.loc
DocumentRoot /PATH/public_html
ErrorLog /PATH/error_log
CustomLog /PATH/access_log combined
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /PATH/public_html>
Options -Indexes +IncludesNOEXEC +FollowSymLinks
allow from all
</Directory>
Alias /project1 "/PATH/public_html/project1"
<Directory "/PATH/public_html/project1">
DirectoryIndex index.html index.htm index.php index.php4 index.php5
Options -Indexes +IncludesNOEXEC +FollowSymLinks
allow from all
</Directory>
Alias /project2 "/PATH/public_html/project2"
<Directory "/PATH/public_html/project2">
DirectoryIndex index.html index.htm index.php index.php4 index.php5
Options -Indexes +IncludesNOEXEC +FollowSymLinks
allow from all
</Directory>
</VirtualHost>
然后,位于/PATH/public_html/project1文件夹中的应用程序将在projects.loc.project1中可用,位于/PATH/public_html/project2文件夹中的申请程序将在projects.loc.project2中可用,依此类推。
我宁愿为不同的应用程序使用不同的子域。这样做的好处是每个子域主机都有自己的配置文件,这也使得错误和访问日志处理更容易。如果您希望每个应用程序都有不同的错误和访问日志,那么使用Alias配置这些日志将更加困难。
进一步阅读:
关于别名:http://httpd.apache.org/docs/current/mod/mod_alias.html
关于ServerPath:http://httpd.apache.org/docs/2.2/vhosts/examples.html#serverpath