1

how would my .htaccess need to look if I wanted subdomains to forward to a specific page "parameter"

eg; http://subdomain.c.example.com > http://c.example.com/page.php?i=subdomain

I can't figure out how the .htaccess works.

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
Richard Sparrow
  • 101
  • 1
  • 12

1 Answers1

3

Try this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.c\.example\.com$ [NC]
RewriteRule . http://c.example.com/page.php?i=%1 [L,R]

Also, in the future when doing examples, use example.com. That domain is provided in the spec for use in documentation, and is guaranteed not to resolve to someone's real domain.

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • Your example didn't work. :-/ this is my domain: foa.me so the file looks like this: RewriteEngine On RewriteCond %{HTTP_HOST} ^(.+)\.cd\.foa\.me$ [NC] RewriteRule . http://cd.foa.me/login.php?c=%1 [L,R] but when i try http://test.cd.foa.me/ it just says it can't find it. – Richard Sparrow Jul 13 '11 at 13:35
  • @TheMeq is `test.cd.foa.me` defined in the DNS? I did a host lookup on it and got no response. Any subdomain you attempt to use must be defined in the DNS or the requesting browser will not be able to associate an IP to it to begin with. – Michael Berkowski Jul 13 '11 at 13:38
  • @TheMeq The subdomain `test.cd.foa.me` must be configured with your domain registrar to point to the same IP that `cd.foa.me` points to (217.23.12.85). You will need to add any subdomains you intend to use into your domain registration control panel. – Michael Berkowski Jul 13 '11 at 13:52
  • so what about if domains are to be generated on the fly? – Richard Sparrow Jul 13 '11 at 13:54
  • @TheMeq See http://stackoverflow.com/questions/586129/create-subdomains-on-the-fly-with-htaccess-php – Michael Berkowski Jul 13 '11 at 14:16