2014-01-09 132 views
0

我有一個關於指向子域到一個目錄的兩個問題:指向子域的「目錄」

  1. 目前我跑的地方,但我可以在我成立了一個假的域中運行我的網站(與主機文件),其名爲mysite.com。我怎麼能(通過服務器設置?)這樣做所有子域將指向/?示例anders.mysite.com也應顯示mysite.com和asdassdd.mysite.com。

  2. 也許1.沒有必要,但我如何通過htaccess將anders.mysite.com指向mysite.com/anders?重要提示是不應該重定向。

爲什麼我認爲的1,是因爲我不想在htaccess的或任何Apache /域設置,該子域是什麼的任何位置指定,因爲這將是動態的(創建由已登錄的用戶在我webapplication)

當前用戶可以使用mysite.com/anders/這是他們創建的URI,而不是真實的目錄。在Kohana bootstrap中,我抓取URI並顯示相關的用戶頁面。

我使用Kohana的MVC框架,並在我的htaccess有這樣的:

# Turn on URL rewriting 
RewriteEngine On 

# Installation directory 
RewriteBase/


# Protect hidden files from being viewed 
<Files .*> 
Order Deny,Allow 
Deny From All 
</Files> 


# Protect application and system files from being viewed 
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L] 
# Allow any files or directories that exist to be displayed directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# Rewrite all other URLs to index.php/URL 
RewriteRule .* index.php/$0 [PT] 

任何幫助表示讚賞!

回答

0

how do i by htaccess point anders.mysite.com to mysite.com/anders ? Important notice is that should not redirect.

您可以使用此規則:

RewriteCond %{HTTP_HOST}:%{REQUEST_URI} ^([^.]+)\.[^:]+:(?!/\1/).*$ 
RewriteRule^/%1%{REQUEST_URI} [L] 
0

爲1,在你的虛擬主機只需添加一個ServerAlias

ServerAlias *.mysite.com 

然後任何子域(包括WWW )將被指向相同的文檔根目錄。

如果你想把子域在自己的目錄(因爲你可以訪問服務器配置),可以使用mod_vhost_aliasVirtualDocumentRoot指令:

VirtualDocumentRoot /path/to/your/htdocs/%1 

所以,如果你要求blah.mysite.com,你會作爲doc根結尾在/path/to/your/htdocs/blah

如果這是你需要的URI不存在的目錄的目錄名的問題,這樣的Kohana可設置路由,你需要確保你已經mod_proxy的加載:

RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTP_HOST} ^([^.]+)\. 
RewriteCond %{REQUEST_URI} !^/%1/ 
RewriteRule ^(.*)$ /%1/$1 [L,P] 

要代理用正確的URI請求Kohana。

+0

我的hosts文件有127.0.0.1 mysite.com和我的httpd-vhosts.conf現在有: <虛擬主機*:80> ServerAlias * .mysite.com 但我仍然無法達到blabla.mysite.com上的文檔根目錄。我錯過了什麼嗎? – Karem

+0

爲了澄清,我的需求是,Kohana應該閱讀blah.mysite.com/page/stuff,因爲它是mysite.com/blah/page/stuff – Karem

+0

因爲我不是真正的mysite。com,我用hosts文件讓瀏覽器認爲我是。 – Karem