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

2023-12-01 0 328

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

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

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

RewriteEngineOn
RewriteBase/

#绑定123.pbhtml.com到子目录dh

RewriteCond%{HTTP_HOST}^123\\.pbhtml\\.com$[NC]
RewriteCond%{REQUEST_URI}!^/dh/
RewriteRule^(.*)$dh/$1?Rewrite[L,QSA]

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

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

<?xmlversion="1.0"encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rulename="ImportedRule1"stopProcessing="true">
<matchurl="^(.*)$"ignoreCase="false"/>
<conditionslogicalGrouping="MatchAll">
<addinput="{REQUEST_FILENAME}"matchType="IsDirectory"ignoreCase="false"negate="true"/>
<addinput="{REQUEST_FILENAME}"matchType="IsFile"ignoreCase="false"negate="true"/>
</conditions>
<actiontype="Rewrite"url="index.php?s={R:1}"appendQueryString="true"/>
</rule>
<rulename="ImportedRule2"stopProcessing="true">
<matchurl="^(.*)$"ignoreCase="false"/>
<conditionslogicalGrouping="MatchAll">
<addinput="{HTTP_HOST}"pattern="^123\\.pbhtml\\.com$"/>
<addinput="{URL}"pattern="^/dh/"ignoreCase="false"negate="true"/>
</conditions>
<actiontype="Rewrite"url="dh/{R:1}?Rewrite"appendQueryString="true"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

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

站长补充

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

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

//强制定义入口文件地址为空
define('SITE_INDEX_DIR','');

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

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悠久资源 Pbootcms教程 巧用伪静态让虚拟主机支持域名绑定到子目录 https://www.u-9.cn/jiaocheng/pbootcms-jiaocheng/15340.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务