使用.htaccess文件,我们可以将指向根目录的域名重定向到子目录中,从而实现一个域名指向一个系统。不过,首先必须确保服务器能够使用.htaccess文件。启用.htaccess,需要修改httpd.conf,启用AllowOverride,并可以用AllowOverride限制特定命令的使用。

一、将域名做一个泛解析*.xxxx.com 解析到你的空间IP,独立IP虚拟主机支持泛解析,不需要绑定域名就可以访问网站。
二、建立bbs 、home 目录,将CMS上传到根目录,将论坛上传到bbs目录,将ucenterHome上传到home目录。
三、打开记事本将以下代码复制进去,保存为.htaccess文件,上传到根目录下。

.htaccess文件内容如下:(以php.la域名为例)

  1. RewriteEngine on
     
  2. DirectoryIndex index.php index.html index.htm
复制代码

2.继续让www.php.la 访问根目录CMS以下htaccess的内容:

  1. RewriteCond %{HTTP_HOST} ^www.php.la$
     
  2. RewriteCond %{REQUEST_URI} !^/
     
  3. RewriteCond %{REQUEST_FILENAME} !-f
     
  4. RewriteCond %{REQUEST_FILENAME} !-d
     

  5.  
  6. RewriteRule ^(.*)$ /$1
     
  7. RewriteCond %{HTTP_HOST} ^www.php.la$
     
  8. RewriteRule ^(/)?$ /index.php [L]
复制代码

3.让home.php.la 访问home目录UcenterHome以下为htaccess的内容:

  1. RewriteCond %{HTTP_HOST} ^home.php.la$
     
  2. RewriteCond %{REQUEST_URI} !^/home/
     
  3. RewriteCond %{REQUEST_FILENAME} !-f
     
  4. RewriteCond %{REQUEST_FILENAME} !-d
     

  5.  
  6. RewriteRule ^(.*)$ /home/$1
     
  7. RewriteCond %{HTTP_HOST} ^home.php.la$
     
  8. RewriteRule ^(/)?$ home/index.php [L]
复制代码

4.让bbs.php.la访问bbs目录论坛以下为htaccess的内容:

  1. RewriteCond %{HTTP_HOST} ^bbs.php.la$
     
  2. RewriteCond %{REQUEST_URI} !^/bbs/
     
  3. RewriteCond %{REQUEST_FILENAME} !-f
     
  4. RewriteCond %{REQUEST_FILENAME} !-d
     

  5.  
  6. RewriteRule ^(.*)$ /bbs/$1
     
  7. RewriteCond %{HTTP_HOST} ^bbs.php.la$
     
  8. RewriteRule ^(/)?$ bbs/index.php [L]
复制代码

按照以上方法可以一个空间建立N个网站,当然也可以把其他顶级域名指向子目录,实现一个空间建立多个网站的功能。