Search code examples
httpbackendcnameweb-development-server

How do Website like craigslist create content depending on the city your computer is located


I am looking to create a website that generates content depending on your city location. The best Example I found was Craigslit.They generate a web domain name like https://yourcity.craigslist.org/ when you either click on the city or it locates where you are. I was just wondering if I could get some help on how to build something like that.


Solution

  • The web pages are created using a template that doesn't change, populated with data that is selected from a database server, using your location to lookup appropriate items.

    The subdomain (your city) is usually defined in the DNS record, just like www. There would be an entry for chicago.craigslist.org, for example.

    edit

    If you're asking how they know where you are, they can take a guess based on your IP address, however this isn't very reliable. Google does this also, when getting you search results that could be localized.