Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Apr 25 '11 at 11:09

This question came from our site for professional and enthusiast programmers.

    
There is, but it's more of a web server and DNS configuration thing than a programming thing. Voting to move to serverfault.com. –  T.J. Crowder Apr 25 '11 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 '11 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 '11 at 8:35

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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