开发者

Managing dynamic sub domains through .htaccess and Clearing all the URLs

I have set the wildcard DNS for my site and now my DNS is forwarding all requests for

*.domain.com to domain.com

What i want in the .htaccess file is that a method to distinguish between the root domain and the dynamic subdomain. if i am using

user1.domain.com

then this should go to

domain.com?users.php?val=user1

and for Other files like the news item the hierarchy should be like

user1.domain.com/news/newsdetails.php to

domain.com/newsdetails.php?val=user1

and it should not disturb the main root domain like my domain.com/newsdetails.php shall go to the newsdetails file without the val variable set.

Basically what the idea here is that i should handle the dynamic subdomains rewriting and the main domain files.

EDIT: i also开发者_高级运维 want that if someone enter www.domain.com then it should pick the index file for this request and if its user1.domain.com then it should be another file.

can any body help me in this issue?


Here are some links that can help:

  • http://blog.voodoochilli.com/2007/01/11/dynamic-sub-domains/
  • http://blog.orite.com.au/web_development/2009-01-22/setting-up-wildcard-virtual-hosts-for-web-development-environment/
  • http://corz.org/serv/tricks/htaccess2.php
  • PHP : dynamic sub domains for each user using htaccess


Here's something I'm using in my prod environment:

# => 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]

I'm almost sure this may work. Of course this will only work with your first URL sample. If you want more stuff, ask for it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜