我们知道一般虚拟主机是不支持绑定到子目录的,这时候该怎么办呢。
我们可以利用伪静态实现将域名或二级域名绑定到子目录,
如果是Apache环境,在站点根目录新建一个文件命名为:.htaccess
下面是 www.dibayun.com域名绑定到子目录dh
RewriteEngine On
RewriteBase /
# 绑定www.dibayun.com 到子目录dh
RewriteCond %{HTTP_HOST} ^www\.dibayun\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/dh/
RewriteRule ^(.*)$ dh/$1?Rewrite [L,QSA]
#可以绑定多个 只需重复上三行代码并更改一下域名、目录名 就好了 如果是windows服务器,在站点根目录新建web.config文件
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?s={R:1}" appendQueryString="true" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www\.dibayun\.com$" />
<add input="{URL}" pattern="^/dh/" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="dh/{R:1}?Rewrite" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>完成以上步骤就可以实现访问www.dibayun.com而直接访问子目录dh了(子目录dh中有index.html或index.php)