0

可能重复:
使用 .htaccess (PHP) 即时创建子域

我想使用.htaccess 具有以下域结构:

domain.com        REWRITES TO   Home Page (index.php)

www.domain.com    REWRITES TO   Home Page (index.php)

blog.domain.com   REWRITES TO   index.php?page=blog

*.domain.com      REWRITES TO   index.php?page=user&id=* (where * can be anything)

有没有办法创造这样的东西?

4

1 回答 1

0

您还没有说明您希望重写使用哪个主机名,所以我假设 www 子域

RewriteCond %{HTTP_HOST} ^([w]{3,3}[.]{1,1}){0,1}domain.com$
RewriteRule ^$ http://www.domain.com/index.php [R,L]

RewriteCond %{HTTP_HOST} ^blog.domain.com$
RewriteRule ^.*$ http://www.domain.com/index.php?page=blog [R,L]

RewriteCond %{HTTP_HOST} !^([w]{3,3}[.]{1,1}){0,1}domain.com$
RewriteCond %{HTTP_HOST} ^([0-9a-zA-Z-]*)[.]domain.com$
RewriteRule ^.*$ http://www.domain.com/index.php?page=user&id=%1 [R,L]
于 2013-01-03T13:12:05.707 回答