Page 1 of 1
create folders and capture results in html file
Posted: Wed Mar 12, 2008 11:00 am
by gurjit
hi
I have a script which
- queries the database for records in cities
what I want to do is:
- create unique folders for each city on the server
- create a index.html page for each folder
so for example:
if I had 5 citys (A,B,C,D,E)
Each city had 10 records.
I would have 5 folders named A,B,C,D each with its own index.html file and 10 results
How can I achieve the snapshot of results?
Re: create folders and capture results in html file
Posted: Wed Mar 12, 2008 11:14 am
by Zoxive
The most common way would to use url rewriting.
Since you have all of the data in the database,
Take this example.
.htaccess file
Code: Select all
RewriteEngine On
RewriteRule ^city/([^/\.]+)/?$ city.php?city=$1 [L] #Route everything after /city/ that does not have a period
city.php
Code: Select all
<?php
$City = !empty($_GET['city'])? $_GET['city'] : NULL;
echo $City;
// Get Data from database..
Then go to yourserver/city/cityname and you will see `cityname` echoed. Using this you can then select the data from the database instead of creating folders and files.
Re: create folders and capture results in html file
Posted: Wed Mar 12, 2008 11:25 am
by RobertGonzalez
Do you really want to create that many folders and files? What happens after 5,000 users have run this script? How do you maintain that?
Re: create folders and capture results in html file
Posted: Wed Mar 12, 2008 11:37 am
by gurjit
Just too confirm:
step 1: create a folder in the root /city
step 2: create the .htaccess file in the root
step 3: in the /city folder create the file city.php with my query and record results, and page layout. I believe this page will get displayed when a city is searched
What will happen. If users are searching on "aber" and then "aberd" - will this create two folders?
The reason for doing this is so we can get indexed better on google. I have noticed a lot of sites indexed have folder structures for cities i.e. they have folders like birmingham/index.html, leeds/index.html, manchester/index.html. If you have any other idea of doing this I would be interested.
Thanks
Re: create folders and capture results in html file
Posted: Wed Mar 12, 2008 12:09 pm
by RobertGonzalez
You do not need to literally make files and directories for each request. Simple URL rewriting can handle that for you (and I think it was already suggested in this thread). If you are on apache you can use mod_rewrite to make some URL rewriting rules so that all requests for
http://mysite.com/city/aber/ will make to index.php?q=city&term=aber.
Re: create folders and capture results in html file
Posted: Wed Mar 12, 2008 12:32 pm
by gurjit
Since the requests are not as folders on the server, when the search engine spider crawls the site it will not find these folders and not index them
Re: create folders and capture results in html file
Posted: Wed Mar 12, 2008 12:51 pm
by RobertGonzalez
The rewrite rules will handle that for you. That is how things are done. Really. Imagine a high traffic site that has millions of "pages" of data. Do you honestly think they make an actual hypertext page for each one?