經過htaccess文件配置多個一級域名指向根目錄的子文件夾

  建立.htaccess文件,在Windows系統建立時要寫成「.htaccess.」,不帶雙引號,不然不會建立成功。php

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
 
    #RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
 
    #綁定 localhost 到 public子目錄
    RewriteCond %{HTTP_HOST} ^localhost$ [NC]
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(.*)$ public/$1?Rewrite [L,QSA]
 
    #綁定 www.abc.com 到 abc子目錄
    RewriteCond %{HTTP_HOST} ^www.abc.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/abc/
    RewriteRule ^(.*)$ abc/$1?Rewrite [L,QSA]
 
    #綁定 hello.com 到 hello子目錄
    RewriteCond %{HTTP_HOST} ^hello.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/hello/
    RewriteRule ^(.*)$ hello/$1?Rewrite [L,QSA]
 
    #綁定 www.xyz.com 到 xyz子目錄
    RewriteCond %{HTTP_HOST} ^www.xyz.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/xyz/
    RewriteRule ^(.*)$ xyz/$1?Rewrite [L,QSA]
</IfModule>
相關文章
相關標籤/搜索