当前位置: 主页 > 文章 >

一个空间搭建多个网站的方法

admin 2024-02-04 161 0条评论

例如:如果你想搭建5个网站,想用的5个域名分别是1.baidu.com 、2.baidu.com、3.baidu.com、4.baidu.com、5.baidu.com

接着看

一、先在WEB目录创建5个目录,目录名自己随意设置,我设置的目录名分别是1、2、3、4、5

二、在空间管理平台点击开启伪静态,然后在WEB目录中创建名为.htaccess的文件。

三、.htaccess文件的内容是(一个域名对应一个目录)

代码从下一行开始

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www.)?1.baidu.com$  

RewriteCond %{REQUEST_URI} !^/1/     

RewriteCond %{REQUEST_FILENAME} !-f     

RewriteCond %{REQUEST_FILENAME} !-d     

RewriteRule ^(.*)$ /1/$1     

RewriteCond %{HTTP_HOST} ^(www.)?1.baidu.com$     

RewriteRule ^(/)?$ 1/ [L]


RewriteEngine on     

RewriteCond %{HTTP_HOST} ^(www.)?2.baidu.comabc.cc$     

RewriteCond %{REQUEST_URI} !^/2/     

RewriteCond %{REQUEST_FILENAME} !-f     

RewriteCond %{REQUEST_FILENAME} !-d     

RewriteRule ^(.*)$ /2/$1     

RewriteCond %{HTTP_HOST} ^(www.)?2.baidu.com$     

RewriteRule ^(/)?$ 2/ [L]


RewriteEngine on     

RewriteCond %{HTTP_HOST} ^(www.)?3.baidu.com$     

RewriteCond %{REQUEST_URI} !^/3/     

RewriteCond %{REQUEST_FILENAME} !-f     

RewriteCond %{REQUEST_FILENAME} !-d     

RewriteRule ^(.*)$ /3/$1     

RewriteCond %{HTTP_HOST} ^(www.)?3.baidu.com$     

RewriteRule ^(/)?$ 3/ [L]


RewriteEngine on     

RewriteCond %{HTTP_HOST} ^(www.)?4.baidu.com$     

RewriteCond %{REQUEST_URI} !^/4/     

RewriteCond %{REQUEST_FILENAME} !-f     

RewriteCond %{REQUEST_FILENAME} !-d     

RewriteRule ^(.*)$ /4/$1     

RewriteCond %{HTTP_HOST} ^(www.)?4.baidu.com$     

RewriteRule ^(/)?$ 4/ [L]


RewriteEngine on     

RewriteCond %{HTTP_HOST} ^(www.)?5.baidu.com$     

RewriteCond %{REQUEST_URI} !^/5/     

RewriteCond %{REQUEST_FILENAME} !-f     

RewriteCond %{REQUEST_FILENAME} !-d     

RewriteRule ^(.*)$ /5/$1     

RewriteCond %{HTTP_HOST} ^(www.)?5.baidu.com$     

RewriteRule ^(/)?$ 5/ [L]

代码在上一行结束

如下图所示

一个空间搭建多个网站的方法


好了,没了,可以访问试试

上面的新教程,原来的教程如下

把您的伪静态规则.htaccess放入空间根目录WEB中,WEB目录新建名为.htaccess的文件,内容为以下内容,根据自己的需要修改目录及域名。.htaccess文件内容如下,只需要修改红色的文字,你的目录是什么就填什么,我的目录是1 2 3 4 5  ,就把下面的代码重复5遍加到.htaccess文件里

.htaccess文件内容如下


RewriteEngine on     

# 把 yourdomain.com 改为你要绑定的域名.     

RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$     

# 把 subfolder 改为要绑定的目录.     

RewriteCond %{REQUEST_URI} !^/1/     

# 不要改以下两行.     

RewriteCond %{REQUEST_FILENAME} !-f     

RewriteCond %{REQUEST_FILENAME} !-d     

# 把 subfolder 改为要绑定的目录.     

RewriteRule ^(.*)$ /1/$1     

# 把 yourdomain.com 改为你要绑定的域名     

# 把 subfolder 改为要绑定的目录.     

# subfolder/ 后面是首页文件index.php, index.html......     

RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$     

RewriteRule ^(/)?$ 1/ [L]

#可以绑定多个 只需重复上三行代码并更改一下域名、目录名 就好了

关于我

搜索