Get page from database with PHP, MySQL and mod_rewrite -
i building own (very small) cms. using php/mysql , mod_rewrite dynamically fetching page requests database.
so far had plain structure like:
domain.com/page
this works fine. want add "folders" or "categories".
the table has needed fields (simplified):
id, name, pid (parent id)
i worked out how build navigational structure database, did not figure out far is, how requested page database using mod_rewrite , php.
- how requested urls
domain.com/folder1/page
or more complexdomain.com/folder1/folder2/folder3/.../foldern/page
- how can differ document "page" in "folder1" document "page" in "foldern"?
- how treat not existing folders, "folder2" in example above?
uhm, little bit helpless @ moment , hope here willing me. :-)
of course googled , searched in stackoverflow, did not find specific help. links tutorials welcome.
thanks in advance & best regards!
the main problem here apache can't talk mysql doesn't know folders or not exist.
the way cmss (like wordpress) solve redirect every request not existing file or directory entry script of cms.
options +followsymlinks -multiviews rewriteengine on rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule .? index.php [l] and in index.php check $_server['request_uri'] see request , handle accordingly.
$parts = explode('/', ltrim($_server['request_uri'], '/')); foreach($parts $part) { // see part for, , if not exist // if find request not exist, send 404 browser // header($_server['http_protocol'].' 404 not found'); }
Comments
Post a Comment