DEVPROCB DEVPROCB - 1 year ago 73
SQL Question

Load Database Data As dynamic Page

How would one go about creating a uri based on the information in the database. I know how I can post to a dynamic php page and have it search the database then use htaccess to rewrite that url. But how do I get php to generate a page based on a URI Link clicked lets say in a menu For example: The database will have a Unique title which will be the unique uri of the portion of the URL, Essentially the title is representative of the link uri in the "a href" link in a menu. So if loads the main page, but if users clicks the link which would be a dynamically generated page. How do I get the server instead of throwing a 404 error because the page does not exist, have php look through the database and load the data from the database and then generate the page based on what was found in the database for "a-dynamic-page"<--unique uri in database? Let me know if you need any clarity on this question.

Answer Source

You probably want to first tell .htaccess to process all missing pages with some php script you've written, by putting this inside your .htaccess file:

<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /my_processor.php [L]

... which would effectively tell apache that all requests to pages that don't exist, should be redirected to a script called my_processor.php, directly on your website's document root.

Once inside the my_processor.php script, you can look at and parse $_SERVER['REQUEST_URI'], and use that to determine what your script should do next. ie:




 default: die("Error");

 case "/some-path-1/":

 case "/some-path-2/":


Please forgive how simple the above is, but hopefully you get the idea.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download