Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Rewriting paging links to static URLs

Quote Reply
Rewriting paging links to static URLs
I'm using mod_rewrite to rewrite some common search queries to static URLs, so that:

/cgi-bin/search.cgi?query=;Options=factor1

becomes

/collections/factor1/


The only problem with this is that all the paging links remain as dynamic cgi URLs. Ideally I would like them to look like they do for categories i.e. /collections/factor1/more2.html etc. I would then figure out a rewrite rule to pick up the '2' value and pass it into the rewrite query string.

I have tried changing the url and page values via the paging array but I haven't been able to get this to work. Any suggestions on if this is possible and where to start would be appreciated.
Quote Reply
Re: [aus_dave] Rewriting paging links to static URLs In reply to
Hi,

In short, its not easy.

I've done it before - but it requires you to write a global that will edit the URL's from the <%toolbar%> tag.

Something like:

Replace search.cgi?query=;Options=factor1;nh=2 with /collectionds/factor1/more2.html

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] Rewriting paging links to static URLs In reply to
Ok...by <%toolbar%> tag I guess you mean <%Links::Utils::paging()%>?

I've tried:

<%set paging.url = 'http://www.domain.com/collections/factor/'%>

in the template which returns:

http://www.domain.com/collections/factor/SCALAR(0x11bae70)?nh=2

in the paging links. I'm guessing that this is why the change can't be done in templates, only in a global? I think I'm on the right track anyway...
Quote Reply
Re: [aus_dave] Rewriting paging links to static URLs In reply to
Hi,

Try:

<%set paging_url = 'http://www.domain.com/collections/factor/'%>
<%set paging_url_new = redo_toolbar($paging_url)%>

..then where you want the toolbar to show:

<%paging_url_new%>

Obivously you need a global (in the above example, redo_toolbar), something like:
Code:
sub {

my $in = $_[0];

# do stuff here to rewrite the URL's

return $in;

}


Hope that helps.

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] Rewriting paging links to static URLs In reply to
Hmm, not sure if we are on the same page Andy...the paging.url bit above is part of the standard paging array within Links (based on what I can see in a template dump). Your solution looks like it doesn't use the standard paging unless I'm missing something.

As you said, it's not easy! It might be best to work out my own paging rewrite global as suggested and dispense with the Links paging althogether. At the end of the day it's only for search engine advantages - users probably won't notice the difference Wink.
Quote Reply
Re: [aus_dave] Rewriting paging links to static URLs In reply to
Hi

In .htaccess file i have :

Code:
RewriteEngine On
RewriteBase /
Options +FollowSymLinks
RewriteRule tag-(.*)\.htm$ /cgi-bin/search.cgi?query=$1

the result:
http://www.mysite/tag-my_quey.html

but i have the same problem than aus_dave, the pagination rewrite.
<%Links::Utils::paging()%>

Maybe someone find a solution since Oct 2007


Thx
Quote Reply
Re: [aus_dave] Rewriting paging links to static URLs In reply to
Hi,

not sure if you solved your problem. I am looking for a similar solution and made a workaround. Maybe it helps you, maybe meanwhile you can suggest a better solution.

in search_results.html template I added the following for paging:

Code:
<%set my_toolbar = Links::Utils::paging()%>
<%if paging.num_hits%><div class="paging"><%my_next_span($my_toolbar)%></div><%endif%>

then I added the following global:

Code:
sub {
my $next_span = shift;
return $next_span unless $ENV{REQUEST_URI} =~ /^\/KEYWORDS-/;
$next_span =~ s/cgi-bin\/search\.cgi\?query=([^;]+);nh=([0-9]+)/KEYWORDS-$1-$2\.html/gm;
$next_span =~ s/%2F/\//g; #not sure why I have to use that but I get 404 otherwise
return $next_span;
}

and finally to .htaccess:

Code:
RewriteRule ^KEYWORDS-(.*)(-([0-9]+))\.html$ /cgi-bin/search.cgi?query=$1&nh=$3; [L]

Regards

Niko