巧用伪静态让虚拟主机支持域名绑定到子目录
作者:小郭博客
时间:2022-12-13 16:42:55
浏览:134
点赞:12
一般虚拟主机是不支持绑定到子目录的,这时候该怎么办呢,其实还可以利用伪静态实现将域名或二级域名绑定到子目录。
如果是Apache环境,在站点根目录新建一个文件命名为:.htaccess,如果已有直接修改增加
下面是123.pbhtml.com域名绑定到子目录dh
RewriteEngine On 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文件,参考以下
<?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="^123\.pbhtml\.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>
完成以上步骤就可以实现访问123.pbhtml.com而直接访问子目录dh了(子目录dh中有index.html或index.php)
文章链接:https://www.pbhtml.com/550.html
文章标题:巧用伪静态让虚拟主机支持域名绑定到子目录
文章版权:PB模板网 (www.pbhtml.com) 所发布的内容,部分为原创文章,转载请注明来源,网络转载文章如有侵权请联系我们!
原文作者:小郭博客 | http://www.d163.net/webknow/48.html
本文最后更新发布于
文章标题:巧用伪静态让虚拟主机支持域名绑定到子目录
文章版权:PB模板网 (www.pbhtml.com) 所发布的内容,部分为原创文章,转载请注明来源,网络转载文章如有侵权请联系我们!
原文作者:小郭博客 | http://www.d163.net/webknow/48.html
本文最后更新发布于
2022-12-13 16:57:21
,某些文章具有时效性,若有错误或已失效,请在下方留言或联系客服:pbhtml@qq.com