.htaccess Problem
Posted: Mon Aug 10, 2009 9:24 am
I'm trying to create a URL rewrite for a website. The rewrite works fine but it seems to ignore the second argument. It rewrites the url from:
index.php?tpl=about&slug=about-kingsdale
to:
/about/about-kingsdale/
The first argument is the template the next is the page url, which is stored (together with the page content) in the db. The problem is if use the rewritten url it completely ignores the second argument and just displays the template, not the content.
.htaccess
The template file:
The get_content function on the page class
index.php?tpl=about&slug=about-kingsdale
to:
/about/about-kingsdale/
The first argument is the template the next is the page url, which is stored (together with the page content) in the db. The problem is if use the rewritten url it completely ignores the second argument and just displays the template, not the content.
.htaccess
Code: Select all
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-]+)/?$ /index.php?tpl=$1 [QSA,L]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ /index.php?tpl=$1&comp=$2 [QSA,L]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ /index.php?tpl=$1&slug=$2 [QSA,L]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ /index.php?tpl=$1&y=$2&m=$3&d=$4 [QSA,L]
</IfModule>Code: Select all
<div id="menu">
<?=$page->list_pages();?>
</div>
<div id="content">
<?=$page->get_content($_REQUEST['slug']);?>
</div>
<div class="clear"></div>Code: Select all
function get_content($slug) {
if(isset($_REQUEST['slug'])) {
$r = $this->db->select("SELECT * FROM content ".
"WHERE slug = '$slug' ".
"LIMIT 1");
} else {
$r = $this->db->select("SELECT * FROM content ".
"WHERE id = '1' ".
"LIMIT 1");
}
$data = $this->db->get_row($r, 'MYSQL_ASSOC');
$html .= "<h1>".$data['title']."</h1>\n";
$html .= $data['content']."\n";
return $html;
}
}