1

Is there a way to make all subdomains show the same page.

I got the idea somewhere you could have a page like idk information.com and if an user typed miami.information.com he would get information from that city.

Is there a way to do it?

Like making the site retrieve the first part of the subdomain and search it on the site.

3
  • There is, but it's more of a web server and DNS configuration thing than a programming thing. Voting to move to serverfault.com. Apr 25, 2011 at 8:17
  • I second that. It's more of a configuration making the subdomains point to a specific url. For example miami.information.com actually points to information.com/miami.
    – Ancide
    Apr 25, 2011 at 8:24
  • I want all subdomains point to the same page, then I can modify the page with php based on the URL. I don't have any idea of how to do it. Could you give me a general direction on where to look for more info?
    – Liso22
    Apr 25, 2011 at 8:35

1 Answer 1

3

The final configuration depends on the web server you'll be using but in Apache httpd you'd simply create a wildcard virtual host:

<VirtualHost *:80>
  ServerName example.com
  ServerAlias *.example.com
  # other configuration directives
</VirtualHost>

Prerequisite is that there's a *.example.com A (or CNAME) resource record in your zone for example.com. Ask your name server administrator about it.

In your PHP scripts you can then simply evaluate $_SERVER['HTTP_HOST'] to get the first component of the hostname.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.