虚拟主机不支持子目录的情况下借助.htaccess实现多个域名重定向到子目录实现单空间多站点

mantou 2021-4-28 413 4/28

举例:
有多个域名:site1.haoduck.comsite2.haoduck.comsite3.haoduck.com
分别在二级目录site1.haoduck.com/site2.haoduck.com/site3.haoduck.com/

.htaccess的代码如下

  1. RewriteEngine On
  2. RewriteCond %{HTTP_HOST} ^site1.haoduck.com$
  3. RewriteCond %{REQUEST_URI} !^/site1.haoduck.com/
  4. RewriteCond %{REQUEST_FILENAME} !-f
  5. RewriteCond %{REQUEST_FILENAME} !-d
  6. RewriteRule ^(.*)$ /site1.haoduck.com/$1
  7. RewriteCond %{HTTP_HOST} ^site1.haoduck.com$
  8. RewriteRule ^(/)?$ site1.haoduck.com/index.php [L]
  9.  
  10. RewriteCond %{HTTP_HOST} ^site2.haoduck.com$
  11. RewriteCond %{REQUEST_URI} !^/site2.haoduck.com/
  12. RewriteCond %{REQUEST_FILENAME} !-f
  13. RewriteCond %{REQUEST_FILENAME} !-d
  14. RewriteRule ^(.*)$ /site2.haoduck.com/$1
  15. RewriteCond %{HTTP_HOST} ^site2.haoduck.com$
  16. RewriteRule ^(/)?$ site2.haoduck.com/index.php [L]
  17.  
  18. RewriteCond %{HTTP_HOST} ^site3.haoduck.com$
  19. RewriteCond %{REQUEST_URI} !^/site3.haoduck.com/
  20. RewriteCond %{REQUEST_FILENAME} !-f
  21. RewriteCond %{REQUEST_FILENAME} !-d
  22. RewriteRule ^(.*)$ /site3.haoduck.com/$1
  23. RewriteCond %{HTTP_HOST} ^site3.haoduck.com$
  24. RewriteRule ^(/)?$ site3.haoduck.com/index.php [L]
- THE END -
最后修改:2021年4月4日
0

非特殊说明,本博所有文章均为博主原创。

共有 0 条评论