2014-01-09 30 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