2011-09-20 52 views
1

我已经设置了通配符DNS为我的网站,现在我的DNS转发是为通过的.htaccess管理动态子域和清除所有

*.domain.comdomain.com

我想什么都请求的URL .htaccess文件是区分根域和动态子域的一种方法。如果我使用

user1.domain.com

那么这应该去

domain.com?users.php?val=user1

和像新闻项目的其他文件的层级应该像

user1.domain.com/news/newsdetails.php

domain.com/newsdetails.php?val=user1

它不应该干扰主根域,就像我的domain.com/newsdetails.php应该去没有val变量集的newsdetails文件。

基本上这里的想法是我应该处理动态子域重写和主域文件。

编辑:我也希望如果有人输入www.domain.com,那么它应该为这个请求选择索引文件,如果它的user1.domain.com那么它应该是另一个文件。

任何机构可以帮助我解决这个问题吗?

回答

1

这里的东西,我用我的督促环境:

# => handle domain names like "prefix.domainname.xx" 
RewriteCond %{HTTP_HOST} (([a-zA-Z0-9\-]+)\.)([a-zA-Z0-9\-]+)\.+(fr|com|net|org|eu)$ 
# - If valid, let's take an example: 
# http://aa.domainname.fr 
# %1 = first group until "." (with it) i.e. "aa." 
# %2 = first group without the "." i.e. "aa" 
# %3 is the domain name i.e. "domainname" 
# %4 is the extension 
# - in %2 = your user id 
RewriteRule $ news/newsdetails\.php newsdetails.php?val=%2 [QSA,L] 

我几乎可以肯定这可能工作。当然这只适用于你的第一个URL样本。如果你想要更多的东西,就问问它。