Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Rewrite rule for review.cgi Pages (SpeedBar)

Quote Reply
Rewrite rule for review.cgi Pages (SpeedBar)
Hi all,

Similar to what's discussed in this thread I've setup a simple mod_rewrite for displaying reviews on search engine friendly URLs except to aviod one long Review page for each link I'm trying to use the page set function Review_SpeedBar.

The htaccess line is:

RewriteRule ^reviews/([0-9]+)_([0-9]+).html?$ cgi-bin/review.cgi?ID=$1;nh=$2 [L]

so any calls to domain.com/reviews/[Link ID Number]_[Review Page Number].html

will pass to this URL:

domain.com/cgi-bin/review.cgi?ID=[Link ID Number];nh=[Review Page Number]

that all works fine, except I'm struggling to change the Review_SpeedBar to write the URLs to match the rewrite URLs.


The Perl that builds the SpeedBar is in /Links/User/Review.pm

Code:
# Generate a toolbar if requested.
my $toolbar;
if ($review_hits > $args->{mh}) {
my $url = $IN->url ( { query_string => 1 } );
$url =~ s/([;&?]?)nh=(\d+)/($1 and $1 eq '?') ? '?' : ''/eg;
$url =~ s/helpful=1//eg;
$toolbar = $DB->html($reviews, $args)->toolbar( $args->{nh} || 1, $args->{mh} || 25, $review_hits, $url);
}
else {
$toolbar = '';
}

Though I can't for the life of me see where I can change this so the URL returned is '[Link ID]_[Review Page Number].html' instead of 'review.cgi?ID=[Link ID];nh=[Review Page Number]

I'm guessing the $toolbar variable passes to a toolbar class in another PM file where the actual html is built?

Any suggestions?

Thanks for your help :)



Comedy Quotes - Glinks 3.3.0, PageBuilder, StaticURLtr, CAPTCHA, User_Edit_Profile

Quote Reply
Re: [Chas-a] Rewrite rule for review.cgi Pages (SpeedBar) In reply to
Hi,

The problem with this, is that its GT::SQL::HTML (I believe) which does the toolbar() function, so its not advised to directly edit the format.

Something you may consider, is a regex to "replace" the URL to what you want, i.e;

Code:
$toolbar = $DB->html($reviews, $args)->toolbar( $args->{nh} || 1, $args->{mh} || 25, $review_hits, $url);

Code:
$toolbar =~ s|\Q$CFG->{db_cgi_url}/review.cgi?ID=\E(\d+?)\;nh=(\d+?)|$CFG->{build_root_url}/$1_$2.html|sig;

Totally untested, but hopefully it'll get you on the right tracks :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Rewrite rule for review.cgi Pages (SpeedBar) In reply to
Hi Andy,

This is how I setup your regex:

Code:
# Generate a toolbar if requested.
my $toolbar;
if ($review_hits > $args->{mh}) {
my $url = $IN->url ( { query_string => 1 } );
$url =~ s/([;&?]?)nh=(\d+)/($1 and $1 eq '?') ? '?' : ''/eg;
$url =~ s/helpful=1//eg;
$toolbar = $DB->html($reviews, $args)->toolbar( $args->{nh} || 1, $args->{mh} || 25, $review_hits, $url);
$toolbar =~ s|\Q$CFG->{db_cgi_url}/review.cgi?ID=\E(\d+?)\;nh=(\d+?)|$CFG->{build_root_url}/$1_$2.html|sig;
}
else {
$toolbar = '';
}

and also tried:

Code:
$toolbar =~ s|\Q$CFG->{db_cgi_url}/review.cgi?ID=\E(\d+?)\;nh=(\d+?)|$1_$2.html|sig;

both output:

review.cgi?;ID=319;nh=1
review.cgi?;ID=319;nh=2

etc. so the URL's stay the same.



Another option i checked was to use a search and replace global and avoid messing with the PM files altogether...

Code:
sub {
# search_replace2
my $search_for_this = shift;
my $replace_with_this = shift;
my $string_to_replace = shift;
$string_to_replace =~ s,$search_for_this,$replace_with_this,g;
my $search_for_this2 = shift;
my $replace_with_this2 = shift;
$string_to_replace =~ s,$search_for_this2,$replace_with_this2,g;
return $string_to_replace;
}

<%search_replace2('review.cgi?;ID=', '', $Review_SpeedBar, ';nh=', '_', $Review_SpeedBar%>

which outputs:

review.cgi?;ID=319_1
review.cgi?;ID=319_2


Agree its not worth messing with the GT::SQL::HTML file as other functions use this and may cause all sorts of grief ;)

Any other suggestions?

ta,

Charlie




Comedy Quotes - Glinks 3.3.0, PageBuilder, StaticURLtr, CAPTCHA, User_Edit_Profile

Quote Reply
Re: [Chas-a] Rewrite rule for review.cgi Pages (SpeedBar) In reply to
Andy,

any idea where your example above could be changed?

thanks.




Comedy Quotes - Glinks 3.3.0, PageBuilder, StaticURLtr, CAPTCHA, User_Edit_Profile