如果你的主机有1G的空间,可以绑定20个域名,只用来放一个网站会不会太浪费啦,那是肯定很浪费的。接下来我们来看看怎么通过htaccess,让不同域名绑定不同子目录,从而实现同一个主机建立多个独立网站。

我们使用.htaccess写入特定规则,就可以一个空间放多个网站,让不同域名进入绑定不同的文件夹:

RewriteEngine On
RewriteBase /
DirectoryIndex index.php index.html index.htm
RewriteCond %{HTTP_HOST} ^(www\.)?help\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/help/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ help/$1
RewriteCond %{HTTP_HOST} ^www.help.com$
RewriteRule ^(/)?$ help/index.html [L]

这样我们就已经把www.help.com这个域名绑定到了help这个子目录上面,相当于help就是一个独立域名主机服务器。


然后用index.html实现域名跳转

<script language="javascript" type="text/javascript">
window.location="http://endv.cn";;
</script>