views:

34

answers:

2

I added the following .htaccess rule:-

RewriteRule ^widgets$ products.php?cat=20 [QSA]

So now I have a simple link called 'widgets' which leads to the 'widgets' category 1st page. However, the links to the 2nd page looks like the following:-

products.php?cat=20&pg=2

What I would like is for the subsequent pages to be rather in the form of:-

widgets?pg=2

The QSA flag in the above .htaccess rule does achieve this, but I need to change the function which generates these page links, otherwise the only way of getting to widgets?pg=2 is by typing it in the browser address bar as:- mywebsite.com/widgets?pg=2.

I think the following PHP function might need to be adjusted, to achieve the result I want. Can any PHP wizards or anyone with appropriate knowledge please help with this. The reason I want to do this is because I want google to index the simple looking pages, rather than the longer ones:-

function writepagebar($CurPage,$iNumPages,$sprev,$snext,$sLink,$nofirstpage){
    $startPage = max(1,round(floor((double)$CurPage/10.0)*10));
    $endPage = min($iNumPages,round(floor((double)$CurPage/10.0)*10)+10);
    if($CurPage > 1)
        $sStr = $sLink . '1' . '" rel="prev"><span style="font-family:Verdana;font-weight:bold">&laquo;</span></a> ' . $sLink . ($CurPage-1) . '">'.$sprev.'</a> | ';
    else
        $sStr = '<span style="font-family:Verdana;font-weight:bold">&laquo;</span> '.$sprev.' | ';
    for($i=$startPage;$i <= $endPage; $i++){
        if($i==$CurPage)
            $sStr .= '<span class="currpage">' . $i . '</span> | ';
        else{
            $sStr .= $sLink . $i . '">';
            if($i==$startPage && $i > 1) $sStr .= '...';
            $sStr .= $i;
            if($i==$endPage && $i < $iNumPages) $sStr .= '...';
            $sStr .= '</a> | ';
        }
    }
    if($CurPage < $iNumPages)
        $sStr .= $sLink . ($CurPage+1) . '" rel="next">'.$snext.'</a> ' . $sLink . $iNumPages . '"><span style="font-family:Verdana;font-weight:bold">&raquo;</span></a>';
    else
        $sStr .= ' '.$snext.' <span style="font-family:Verdana;font-weight:bold">&raquo;</span>';
    if($nofirstpage) $sStr = str_replace(array('&amp;pg=1"','?pg=1"'),'" rel="start"',$sStr);
    return($sStr);
}

If it helps to know how the writepagebar function fits into the incproducts.php which itself sits inside the products.php page you can see here:-

http://freetexthost.com/3ubiydspzm

A: 

Analyzing your code, it seems that $sLink is who contains the 'products.php?cat=20' value, the function only appends the page value, so maybe you need to modify another function.

In other words, your writepagebar() only appends the page number to the generated link. You must search who is calling writepagebar() with the 'products.php?cat=20' string and modify at that level.

clinisbut
A: 

Edited after comments from "nitbuntu":-

In the function just instead of these lines:-

    $sStr = str_replace(array('&amp;pg=1"','?pg=1"'),'" rel="start"',$sStr);
    return($sStr);
}

write the following lines:-

    $sStr = str_replace('products.php?cat=20', 'widgets', $sStr);
    $sStr = str_replace('&amp;pg=', '?pg=', $sStr);
    $sStr = str_replace(array('&amp;pg=1"', '?pg=1"'), '" rel="start"', $sStr);
    return($sStr);
}

Hope it helps.

Knowledge Craving
nitbuntu
I'll test that out. But will this only work for 'widgets'. If I needed to do it for a few more pages. For example, if I also had another page called 'doodles' which corresponds to 'products.php?cat=21'....and another called 'dogs' which corresponds to 'products.php?cat=22'. Would I just append additional lines in the code?
nitbuntu
Well answer to my above comment is 'yes' it seems. For 'doodles' I just added '$sStr = str_replace('products.php?cat=21', 'doodles', $sStr);'. Brilliant, Thanks!
nitbuntu
@nitbuntu - Sorry, I couldn't answer to your last comment quick enough. But yes, you will require to add additional lines in the code. Thanks that you got a grip.
Knowledge Craving