I am using a PHP form to query a MySQL DB. The query result is displayed in pagination (100 results/page). I want that the pagination be converted to static html pages automatically. That is, instead of showing the result as www.abc.com/query.php?page=1 it should produce results as 1.html, 2.html such that simply copying them on my site will produce pages with URL like: www.abc.com/files/1.html www.abc.com/files/2.html ..........and so on.
chandubhai is right best way to do this what you want is use mod_rewrite to rewrite your url's to seo friendly urls
Create a .htaccess file, and put in the root of the directory you want to redirect: RewriteEngine on RewriteRule ^files/(.*)/$ /query.php?page=$1 [R,L] Then have your links written in the format abc.com/files/1/ abc.com/files/2/ abc.com/files/3/ etc. the rewrite rule then converts the /files/1/ to query.php?page=1 etc No need to convert anything to a static html page (seems a little pointless anyway).
You can use mod_rewrite but he may want to write the pages to static html to avoid hitting the database for every page generation. If that is the case youll need to cache the pages to disk/memory using php on first display or write them to disk as theyre processing.
Tonybogs you are write. I want static pages so that the load on database is reduced. Could you please help me with the code? Thanks for help.
IMO the best thing to do is place in .htaccess is what popular systems like Wordpress, mambo/joomla, etc. use. <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> Code (markup): This will redirect all requests that aren't actually a physical file to index.php. Then index.php can handle the request, with something like $var_array = explode("/", $_SERVER['REQUEST_URI']); //Ignore the first element which I think is always blank, so start with $i=1 for($i=1; $i<count($var_array); $i++) { //process each variable if necessary } PHP: The actual code you should use might be a bit more complicated, and I think if your server is IIS you might need to use different server variables. Also you might want to check for magic quotes with get_magic_quotes_gpc() and strip them if true (before doing the code above), but if you don't plan to move to another server ever this is optional. In your case I believe $var_array[1] will be 'files' and $var_array[2] will be '1', '2', '3', etc. Then your index.php can display content based on $var_array[2].
Hmmm...I read this before posting but for some reason it didn't sink in. If you want actual html pages automatically generated then you'd need some sort of caching solution, yes. You can probably do a search somewhere for 'caching class'; I don't have experience with one myself but you can probably find one on pear.php.net or phpclasses.org. But unless server load is a huge issue for you I'd recommend the dynamic route with PHP, because it's much more flexible. Tough to edit a 100 paginated HTML pages, and odds are pretty good that someday you'll want to.