Apache 下更改 DocumentRoot 和新建虚拟目录

Apache 安装后,默认的 DocumentRoot 是安装目录下的 htdocs 目录,编程时有很多不便,如需更改,打开安装目录 conf 子目录下的 httpd.conf 文件,修改 DocumentRoot 属性即可,如更改为:DocumentRoot “E:/My/DocRoot”。

在 IIS 下,新建虚拟目录可通过可视化界面操作,在 Apache 中,新建虚拟目录通过修改 httpd.conf 文件实现。

在 httpd.conf 的 alias_module 下增加一别名定义项,如:Alias “/onefly” “E:/My/Onefly” ,即可定义虚拟目录。

更改以上设置后,必须重启 Apache 才能使设置生效。同时,要对相应目录作权限定义,否则会出现无权访问的错误提示。

要对目录定义权限,可在 httpd.conf 文件中定义类似以下的代码:

<Directory “E:/My/Onefly”>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

=======================================================================

自己机器上配置实例如下:

[plain] view plaincopy
 
    1. <IfModule alias_module>  
    2.     #  
    3.     # Redirect: Allows you to tell clients about documents that used to   
    4.     # exist in your server's namespace, but do not anymore. The client   
    5.     # will make a new request for the document at its new location.  
    6.     # Example:  
    7.     # Redirect permanent /foo http://www.waydu.com/bar  
    8.   
    9.     #  
    10.     # Alias: Maps web paths into filesystem paths and is used to  
    11.     # access content that does not live under the DocumentRoot.  
    12.     # Example:  
    13.     # Alias /webpath /full/filesystem/path  
    14.     ##################################################################  
    15.      Alias   /study   "D:/PHP/www/study"    
    16.     <Directory   "D:/PHP/www/study">     
    17.               Options   Indexes   Includes   FollowSymLinks   MultiViews   IncludesNoExec     
    18.               AllowOverride   None     
    19.               Order   allow,deny     
    20.               Allow   from   all     
    21.     </Directory>    
    22.     ##################################################################  
posted @ 2015-10-20 12:41  jasononline  阅读(482)  评论(0)    收藏  举报