举例:
有多个域名: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