Page 1 of 1

.htaccess Problem

Posted: Mon Aug 10, 2009 9:24 am
by bluefusionstudios
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

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>
The template file:

Code: Select all

<div id="menu">
    <?=$page->list_pages();?>
</div>
 
<div id="content">
    <?=$page->get_content($_REQUEST['slug']);?>
</div>
 
<div class="clear"></div>
The get_content function on the page class

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;
    }
}

Re: .htaccess Problem

Posted: Tue Aug 18, 2009 4:46 am
by mrvijayakumar
It will not work, because you are passing argument /about/about-kingsdale/ with special character "-". Remove the special character (-) and try. As per htaccess, '-' character will consider as whitespace. Due to this, you will not get expected result.

Thanks

Vijaya Kumar S,
Web Developer, +91 9952838699
http://www.vijayakumar.org,