2014-03-28 79 views
1

動態子域我試圖創建自定義域名處理在.htaccess

下面是我在做什麼

http://username.mydomain.com正在訪問http://mydomain.com/live/agent/index.php?agent_user_name=username(工作正常)

這裏的.htaccess

RewriteEngine on 

RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC] 

RewriteCond %1 !^www$ [NC] 

RewriteRule ^$ /live/agent/index.php?agent_user_name=%1 [L] 

但現在我想處理其他頁面以及

http://username.mydomain.com/blog應該訪問 http://mydomain.com/live/agent/blog.php?agent_user_name=username

請幫助如何在.htaccess處理這個問題,以及

回答

1

你可以有這樣的附加規則:

RewriteEngine on 

RewriteCond %{QUERY_STRING} ^$ 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC] 
RewriteRule ^/?$ /live/agent/index.php?agent_user_name=%1 [L] 

RewriteCond %{QUERY_STRING} ^$ 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC] 
RewriteRule ^(.+?)/?$ /live/agent/$1.php?agent_user_name=%1 [L] 
+0

那麼,它給了服務器配置錯誤/內部錯誤 – imran

+0

現在嘗試更新規則 – anubhava

+0

是的,它像一個魅力:)非常感謝你 – imran