2012-07-09 20 views

回答

0

爲什麼要使用的.htaccess?你可以用PHP來做到這一點。

<?php 
$url = 'http://www.'. $_GET['name'] .'.example.com'; 

header('Location: '. $url); 
?> 

只要確保在使用header()之前不輸出任何文本。

要從子域URL獲取名稱,請執行以下操作。

<?php 
$new_url = $_SERVER["SERVER_NAME"]; 
$url_parts = explode('.', $new_url); 

echo 'Name is: '. $url_parts[0]; 
?> 

james.example.com結果爲「Name is:james」。

+0

是的...但我仍然希望能夠得到名稱trought得到當我在子域 – 2012-07-09 11:06:52

+0

您可以使用$ _SERVER [「SERVER_NAME」],然後爆炸該點上的字符串,並得到從結果數組中獲取名稱。 – Werner 2012-07-09 11:14:07

+0

我在上面添加了一個例子... – Werner 2012-07-09 11:21:43