Linux

虚拟主机绑定多个域名

Posted on 2020-09-28,3 min read
  • 一般大部分便宜的虚拟主机都不支持多个子目录,但是可以通过设置重写的方法来设置。

IIS

  • 修改web.config

    • <?xml version="1.0" encoding="UTF-8" ?>
      <configuration>
          <system.webServer>
              <handlers>
                  <remove name="PHP-7.4-7i24.com" />
                  <remove name="PHP-7.3-7i24.com" />
                  <remove name="PHP-7.2-7i24.com" />
                  <remove name="PHP-7.1-7i24.com" />
                  <remove name="PHP-7.0-7i24.com" />
                  <remove name="PHP-5.6-7i24.com" />
                  <remove name="PHP-5.5-7i24.com" />
                  <remove name="PHP-5.4-7i24.com" />
                  <remove name="PHP-5.3-7i24.com" />
                  <remove name="PHP-5.2-7i24.com" />
                  <add name="PHP-5.6-7i24.com" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="c:\php\5.6\php-cgi.exe" resourceType="Either" />
              </handlers>
              <rewrite>
                  <rules>
                      <rule name="名称">
                          <match url="^.*$" ignoreCase="false" />
                          <conditions>
                              <add input="{HTTP_HOST}" pattern="^子域名$" />
                          </conditions>
                          <action type="Rewrite" url="子目录路径/{R:0}" appendQueryString="true" />
                      </rule>
                  </rules>
              </rewrite>
          </system.webServer>
          <system.web>
              <customErrors mode="Off" />
              <compilation debug="true" />
              <identity impersonate="false" />
          </system.web>
      </configuration>
      

    Apache

    • 修改.htaccess

      • <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        # 绑定www.xxx.com到子目录htaccess
        RewriteCond %{HTTP_HOST} ^www\.xxx\.com$ [NC]
        RewriteCond %{REQUEST_URI} !^/htaccess/
        RewriteRule ^(.*)$ htaccess/$1?Rewrite [L,QSA]
        #可以绑定多个,只需重复上三行代码并更改一下域名、目录名就行了
        </IfModule>
        

下一篇: 设计模式-适配器模式→

loading...