Gossamer Forum
Home : General : Perl Programming :

edit goto.cgi

Quote Reply
edit goto.cgi
I would like to have an option so if the url in by database is like: file=test.pdf i redirect to another location. But's it not working...


if ($goto =~ s/^file=//i)
{
Location: /cgi-bin/redirect.cgi?$goto\n\n;
}
else
{
Location: $goto\n\n;
}
Quote Reply
Re: edit goto.cgi In reply to
Don't use substitutions, use matches:

if ($goto =~ m/^file=/i) {
#BLAH
}

I think you want the code to substitute "file=" with nothing and then use that value to perform the action you desire. This probably won't work, because the value in // is undefined, which means no replacement will occur. You could try:

if ($goto =~ s/^file=/\?/i) {
Location: /cgi-bin/redirect.cgi$goto\n\n;
} else {
Location: $goto\n\n;
}

Let me know if this works.





------------------
Fred Hirsch
Web Consultant & Programmer
Quote Reply
Re: edit goto.cgi In reply to
f ($goto =~ s/^file=/\?/i) {
Location: /cgi-bin/redirect.cgi$goto\n\n;
} else {
Location: $goto\n\n;
}

<reply>
Let me know if this works.

It didn't work, the output from: file=test is
---> ?test <--

<reply>
I think you want the code to substitute "file=" with nothing and then use that value to perform the action you desire.

The script first have to check if it starts with file=, because i alsow have normal http:// urls in my database.

Quote Reply
Re: edit goto.cgi In reply to
Okay,

I think after reading more on substitutions (which I don't do an awful lot), you could do this:

if ($goto =~ s/^file=(.+)/$1/i) {
print "Location: /cgi-bin/redirect.cgi$goto\n\n";
} else {
print "Location: $goto\n\n";
}

That should work fine.


------------------
Fred Hirsch
Web Consultant & Programmer