2013-01-03 55 views
0

可能重複:
Create Subdomains on the fly with .htaccess (PHP)如何使用.htaccess創建動態子域?

我想有以下的域結構的.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) 

有沒有一種方法來創建這樣的事?

+0

退房哪些主機[此鏈接。(http://stackoverflow.com/questions/586129/ create-subdomains-on-the-fly-with-htaccess-php)這是另一個像你的問題,有一個很好的答案。 – phpisuber01

回答

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]