2010年6月4日

21:23

别名(虚拟目录)是将网站文档目录以外的目录挂载到网站站点根目录下的方法。完成后,只能使用URL地址去访问。例如:

网站别名目录与文件系统目录对应表

网站目录        文件系统目录

/         /var/webroot

/public         /var/website/

通常在浏览器地址栏中输入:http://192.168.152.100,显示网站根目录的内容。若在地址栏中输入:http://192.168.152.100/public 就会显示/var/www/html/abc下的内容。具体步骤如下:

  1. 准备工作。在/var/website目录下创建一个index.html文件内容如下,原网站根目录下的文件已经有了,就不在去创建:

[root@localhost abc]# cat index.htm

<html>

<head>

<title>

This is public directory!

</title>

</head>

<body>

<h1>This is http://192.168.152.100/public.<br>Directory is /var/website

</body>

</html>

  1. 修改/etc/httpd/conf/httpd.conf文件,在Alias段加入如下内容

Alias /public "/var/website/"

<Directory "/var/website">

Options Indexes MultiViews

AllowOverride None

Order allow,deny

Allow from all

</Directory>

  1. 重新启动Apache服务器,测试结果

[root@localhost abc]# service httpd restart

  1. 打开firefox浏览器,在地址栏中输入http://192.168.152.100/public

Apache的应用二----设置虚拟目录_Apache