PDA

View Full Version : Wanted: Redirection script


Xero
09-01-2004, 08:45 AM
Hello.

I have been searching for a script for long but in vein.
Can anybody recommends me some examples?
Here is a brief description of what I want:

I want the script to redirect visitors to different page according to the request included in the hyperlink.

For example, if a request of 'default' is received, the script has to redirect visitors to the page 'index.htm'.

Is there any script doing this? Thanks.

reubenb
09-01-2004, 10:37 AM
#!/usr/bin/perl
print "Location: http://yoursite/index.htm\n\n";


That should do the trick. (save it as a .pl)

Xero
09-01-2004, 11:07 AM
Thanks for reply ... but that isn't what I mean ... perhaps I could explan it further.

In a file (let's say a *.pl file), there is a group of pre-defined commands and their respective location.

For example,

Command | Destination
---------------------------------------
index | default.htm
products | products.htm
about | about.htm
download | download.htm
contact | contact.htm
-----------------------------------------

Then when a hyperlink containing the command 'index'
(i.e. redirect.pl?command=products (or something like that), then the visitor will be redirected to products.htm.

Similarly, when the command is 'contact' (redirect.pl?command=contact), then the visitor will be redirected to contact.htm.

Thanks again.

reubenb
09-02-2004, 01:48 PM
Oh, sorry about that - I thought that's what you meant.

I'm not really sure how to do this, but I think its something like this..
you need to create a query string
to call the 'action=whatever'
and then tell it what to do.

i know how to do it in PHP and ASP but not Perl.. sorry :(

Xero
09-02-2004, 01:54 PM
Never mind ... my server supports ASP as well.
Could you show me how to do this?

Thanks very much! :)

reubenb
09-02-2004, 02:11 PM
Sure..
I think they should move this to the ASP forum though too...?

This might be what you're looking for.. if not, ill change it accordinly...


<%command = request("command")%>

<%if command="contact" then%>
<%Response.Redirect("contact.htm")%>

<%elseif command="download" then%>
<%Response.Redirect("download.htm")%>

<%elseif command="products" then%>
<%Response.Redirect("products.htm")%>

<%elseif command="about" then%>
<%Response.Redirect("about.htm")%>

<%elseif command="contact" then%>
<%Response.Redirect("contact.htm")%>

<%end if%>

Xero
09-03-2004, 05:26 PM
Ah yes ... this seems to be what I mean. Thanks very much.

But could you show me how to use this code? (i.e. how to embed this code into a htm / asp file) I am an idiot in ASP programming ...

Thanks again.

andyede
09-24-2004, 11:25 AM
in perl you want something like


use CGI 'standard';

$request = param('request');

if ($request eq 'request1') {
print redirect('domain1');
}elsif ($request eq 'request2') {
print redirect('domain2');
}else{
print redirect('defaultDomain');


OR

If the request URL is going to hold data that can link directly to the file or path you want to use then



use CGI 'standard';

$request = param('request').'.html';

print redirect($request)


or a variation of the theme

bazz
12-22-2004, 11:04 AM
#!/usr/bin/perl
print "Location: http://yoursite/index.htm\n\n";


That should do the trick. (save it as a .pl)

edit: Nooooob question. I didn't know I had to delete the Content Type text/html line.

bazz