.htaccess Problem

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
bluefusionstudios
Forum Newbie
Posts: 3
Joined: Fri Jul 24, 2009 10:16 am
Location: London

.htaccess Problem

Post 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;
    }
}
User avatar
mrvijayakumar
Forum Commoner
Posts: 58
Joined: Tue Aug 18, 2009 12:39 am
Location: Chennai city, India
Contact:

Re: .htaccess Problem

Post 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,
Post Reply