Currently the states and cities are shown this way: example.com/-5-California or example.com/294-Dayton-Springfield or example.com/22-Fort-Smith or example.com/-35-New-York etc... I want to get them changed via .htaccess to: california.example.com or daytonspringfield.example.com or fortsmith.example.com or newyork.example.com etc... The numbers for states and cities: States: $row['countryid'] Cities: $row['cityid'] The names for states and cities: States: $row['countryname'] Cities: $row['cityname'] How would you create dynamic subdomains using this information? Thanks!
As you will have to customize your code anyway, there is no need of .htaccess for that, an easy way is simply to add a DNS record for *, then using PHP you can take the "hostname" used, follow my example: $host_name = explode('.',$_SERVER['SERVER_NAME']); if ( (count($host_name) == 3) AND (strtolower($host_name[0]!=="www")) ) { //We Got a Subdomain $value=strip_tags($host_name[0]); //Let's always clean the input... $query = mysql_query("SELECT countries.countryid as state,cities.cityid as city FROM countries,cities WHERE (cities.name LIKE '$value' OR countries.name LIKE '$value')"); $data = mysql_fetch_array($query); echo "<pre>".print_r($data,true)."</pre>"; //If value is equal to a city we will get an array like this: //Array ( city => 44, state => 0) //If value is equal to a state we will get an array like this: //Array ( city => 0, state => 32) //If we get no matches then we can simply show the homepage again: //Array ( city => 0, state => 0) --> include "homepage.php"; //Other Code here... } else { //We Got a Regular Domain //Let's show the homepage... } Code (markup): Mind this code is raw, can be optimised and can be really powerful to do what you need.
Thank you for your input. It looks like it may work but I am not sure. Will test it later. Is it something you used in the past and it worked?