使用伪静态让虚拟主机支持域名绑定到子目录

作者:米云网络 时间:2023-09-01 浏览:653
653

一般虚拟主机是不支持绑定到子目录的,这时候该怎么办呢,其实还可以利用伪静态实现将域名或二级域名绑定到子目录。

如果是Apache环境,在站点根目录新建一个文件命名为:.htaccess,如果已有直接修改增加

下面是123.symiyun.com域名绑定到子目录dh

  1. RewriteEngine On

  2. RewriteBase /

  3.   

  4. # 绑定123.symiyun.com到子目录dh


  5. RewriteCond %{HTTP_HOST} ^123\.symiyun\.com$ [NC]

  6. RewriteCond %{REQUEST_URI} !^/dh/

  7. RewriteRule ^(.*)$ dh/$1?Rewrite [L,QSA]


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


如果是windows服务器,在站点根目录新建web.config文件,参考以下

  1. <?xml version="1.0" encoding="UTF-8"?>

  2. <configuration>

  3.     <system.webServer>

  4.         <rewrite>

  5.             <rules>

  6.                 <rule name="Imported Rule 1" stopProcessing="true">

  7.                     <match url="^(.*)$" ignoreCase="false" />

  8.                     <conditions logicalGrouping="MatchAll">

  9.                         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />

  10.                         <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />

  11.                     </conditions>

  12.                     <action type="Rewrite" url="index.php?s={R:1}" appendQueryString="true" />

  13.                 </rule>

  14.                 <rule name="Imported Rule 2" stopProcessing="true">

  15.                     <match url="^(.*)$" ignoreCase="false" />

  16.                     <conditions logicalGrouping="MatchAll">

  17.                         <add input="{HTTP_HOST}" pattern="^123\.symiyun\.com$" />

  18.                         <add input="{URL}" pattern="^/dh/" ignoreCase="false" negate="true" />

  19.                     </conditions>

  20.                     <action type="Rewrite" url="dh/{R:1}?Rewrite" appendQueryString="true" />

  21.                 </rule>

  22.             </rules>

  23.         </rewrite>

  24.     </system.webServer>

  25. </configuration>

完成以上步骤就可以实现访问123.symiyun.com直接对应子目录dh了。

站长补充

pbootcms在使用中发现子目录对应的站点url中会自动带上目录名称,例如上面的dh,变成123.symiyun.com/dh/

只要给indx.php里增加下面一段代码即可解决(在线升级后需要重新添加或者升级时不要选择覆盖这个文件)

  1. // 强制定义入口文件地址为空

  2. define('SITE_INDEX_DIR''');

V91J%IVYZ%GE4Q_F9MH(BDQ.png


文章链接:https://www.yunscrm.cn/help/126.html
文章标题:使用伪静态让虚拟主机支持域名绑定到子目录
声明: 所发布的内容,部分为原创文章,转载请注明来源,网络转载文章如有侵权请联系我们!

相关阅读