1

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?

HardCode
  • 1,613
  • 4
  • 21
  • 42

2 Answers2

1

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.

Olivier Pons
  • 15,363
  • 26
  • 117
  • 213