Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Rewrite rule

Quote Reply
Rewrite rule
Using the ReWriteEngine, I have tried to create a rule that would alias a short path to longer path in a case insensitive manner. Ins that possible? What I tried seemed to work, but in some cases entered what must have been a loop.

http://postcards.com/FAQ/

to

http://postcards.com/cgi-bin/FAQ/page.cgi

Is there a way to make the 'FAQ' portion case insensitive? So that if a user types http://postcards.com/faq they will also get rewritten?

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: Rewrite rule In reply to
How bout:

RewriteRule /[fF][aA][qQ] /cgi-bin/FAQ/page.cgi [L]

However, make sure you don't have anything else on your site that starts with /faq as otherwise it'll get rewritten.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Rewrite rule In reply to
Alex,

I couldn't get that to work.

On a related issue, I kept playing and I was able to get this to work, without entering the previous loop. Is it doing what I think it's doing?

RewriteRule /(D|d)omains?/?$ http://pugdog.com/cgi-bin/Domains/page.cgi [R,L]

It should be sending 'domain', 'domains', 'Domain', 'Domains' to the rewritten URL, but ignoring the pattern match if anything is entered after the optional 's/'



PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: Rewrite rule In reply to
Pugdog, currently when I click a link in my directory it says this:

http://www.audio-grabber.com/cgi-bin/j*?ID=1

..how can I get it to work like this:

http://www.audio-grabber.com/cgi-bin/j*?URL=http://www.blabla.com

I'd obviously have to add <%URL%> in link.html to replace the <%ID%>, but there is some code that needs to be altered in jump.cgi and im not sure how to do it. Could you tell me please?

Code that needs to be changed...

# Otherwise, if we have a link, let's look it up.
elsif (defined $id) {
if ($idb !~ /^\d+$/) {
print $IN->header();
print Links::SiteHTML::display ('error', { error => Links::language ('JUMP_INVALIDID', $id) });
return;
}
$rec = $db->get ($id);
if (! $rec) {
print $IN->header();
print Links::SiteHTML::display ('error', { error => Links::language ('JUMP_INVALIDID', $id) });
return;
}
$goto = $rec->{URL};


I tried this but it doesnt work...

# Otherwise, if we have a link, let's look it up.
elsif (defined $URL) {
if ($URL) {
print $IN->header();
print Links::SiteHTML::display ('error', { error => Links::language ('JUMP_INVALIDURL', $URL) });
return;
}
$rec = $db->get ($URL);
if (! $rec) {
print $IN->header();
print Links::SiteHTML::display ('error', { error => Links::language ('JUMP_INVALIDURL', $URL) });
return;
}
$goto = $rec->{URL};




Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Rewrite rule In reply to
Jump.cgi has been my favorite script to mod.

I wouldn't have changed anything, but ADDED the extra test.

You are passing in ?URL= instead of ?ID=

If you look at the top of the script, there is an assignment:


$id = $IN->param('ID');

You are looking at the passed parameter 'ID'.

You'd need to add:


$url = $IN->param('URL');


And, then, add an

} elsif ($url) {....}

do something.

That would save a lookup, but it would also mean people can pass in bogus values. By passing in the ID and checking for it, you are pulling the URL from the database so there is no tampering

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: Rewrite rule In reply to
Ahh..right ok...thanks for telling me how to do it anyway...

Can you not get it to check the URL against url.db to check it is valid and if not give an error like "You are trying to visit a URL that isnt in our db" ?

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Rewrite rule In reply to
Why not just pass in the ID then? The look up is no more expensive to get the URL than the compare it.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: Rewrite rule In reply to
I suppose....just wanted it to look similar to Yahoo...

http://srd.yahoo.com/srst/29999920/napster/5/30/*http://napstersucks.cjb.net/

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Rewrite rule In reply to
Hi,

I just found the NC flag which should help. It makes all paterns case insensitive, so you should be able to do:

RewriteRule /faq /cgi-bin/faq/page.cgi [L,NC]

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Rewrite rule In reply to
I still can't get that sort of pattern to work.

The following two rules work, or appear to:

RewriteRule /(D|d)omains?/?$ http://pugdog.com/cgi-bin/Domains/page.cgi [R,L]
RewriteRule /(F|f)(a|A)(q|Q)/?$ http://pugdog.com/LinkSQL/pages/ [R,L]

The following rules don't work, and give a 404 error.

RewriteRule /faq /LinkSQL/pages/ [L,NC]
RewriteRule /domains /cgi-bin/Domains/page.cgi [L,NC]






PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: Rewrite rule In reply to
Hmm, does:

RewriteRule /faq http://pugdog.com/LinkSQL/pages [R,L,NC]

work?

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Rewrite rule In reply to
Yes, that works.

I wonder if that means it needs rewritebase set?



PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: Rewrite rule In reply to
Hi,

Hmm, the [R] flag tells rewrite to send an actual redirect to the client, not what you want to do typically as it involves an extra request. What's happening is unless you put the [R] there with the full URL, it's rewriting to a different domain, very strange. You should look at your error logs to see what the 404 error says, what it tried to request, and what domain, etc.

Hope that helps,

Alex

--
Gossamer Threads Inc.