Forum Moderators: coopster
1. Use ModRewrite to send all requests that are not images or css files to index.php
In an .htaccess file put:
RewriteEngine on
RewriteRule!\.(gif¦jpg¦png¦css)$ index.php
Then in index.php do something like this:
<?php
$uri=strip_tags($_SERVER['REQUEST_URI']);$query="SELECT id,title,description,content FROM pages WHERE uri='$uri'";
$result=mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows == 0) { echo 'Error: No Matching Page'; }
$page=mysql_fetch_assoc($result);
?>
<html>
<head>
<title><?php echo $page['title'];?></title>
<meta name="description" content="<?php echo $page['description'];?>" />
</head>
<body>
<?php echo $page['content'];?>
</body>
</html>
In the database you would have something like
id ¦ URI ¦ page_title ¦ description ¦ content ¦
1 ¦ /mypage.html¦My Super Page ¦ My page is about... ¦ Pagecontent here¦
# Table structure for table `pages`
#CREATE TABLE `pages` (
`id` smallint(5) unsigned NOT NULL auto_increment,
`uri` varchar(255) NOT NULL default '',
`title` varchar(255) NOT NULL default '',
`description` varchar(255) NOT NULL default '',
`content` mediumtext NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uri` (`uri`),
FULLTEXT KEY `fulltext_index` (`title`,`content`,`description`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;
#
# Dumping data for table `pages`
#
INSERT INTO `pages` VALUES (1, '/mypage.html', 'Title of Page', 'A small but growing collection or original pages by various authors', 'Welcome to my page!');
The above code is not all tested. If you have any problems or questions feel free to post back and I'll try to help. ;)
Elijah