---
title: "Redirectat"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/19177-redirectat"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "acidfred"
published: "2000-09-23T18:07:00.000Z"
updated: "2000-09-25T06:32:00.000Z"
replies: 7
views: 420
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/19177-redirectat"
---

# Redirectat

## #1 — acidfred, 2000-09-23T18:07Z

I asp finns funktionen
response.redirect

som skickar användaren till en ny sida, när man har kört den kod som behövs.

Kan man göra så med perl åxå?
/fred

Permalänk: https://www.webforum.nu/p/19177

## #2 — stevenet, 2000-09-23T18:27Z

```
#!/usr/bin/perl
$ny_sida = "http://www.webforum.nu";
print "Location: $ny_sida\n\n";
exit;
```

Permalänk: https://www.webforum.nu/p/341147

## #3 — acidfred, 2000-09-24T04:37Z

Jag får det inte att fungera...den bara skriver ut adressen...som text asså

Vad gör jag för fel?
/fred

Permalänk: https://www.webforum.nu/p/341148

## #4 — stevenet, 2000-09-24T07:26Z

Testa någon av följande:

Kod 1:

```
#!/usr/bin/perl
print "HTTP/1.0 302 Temporary Redirection\r\n" if $ENV{PERLXS} eq "PerlIS";
$ny_sida = "http://www.webforum.nu";
print "Location: $ny_sida\n\n";
exit;
```

Kod 2:

```
#!/usr/bin/perl
print "Content-type: text/html\n";
$ny_sida = "http://www.webforum.nu";
print ("Location: $ny_sida\n\n");
exit;
```

Permalänk: https://www.webforum.nu/p/341149

## #5 — Peter_B, 2000-09-24T08:42Z

Du måste vara noga med att "Location: \<A HREF="http://ny_location...\\n\\n"" TARGET=\_blank\>http://ny_location...\\n\\n"\</A\>  är det första och enda som kommer ur programmet (med undantag för cookies och annat förstås.. men absolut ingen Content-type: text/html).

tänk även på att inte avsluta http-headern för tidigt. i exemplet ovan avslutas headern med ett extra \\n, men på tidigare rader skall det bara vara ett \\n, inte två. 

prova att bara skriva ett litet testprogram på några rader. då kan du testa precis vad som händer, och ta dina erfarenheter med dig vidare till större projekt. det där lät väl bra? :)

Peter Bredlöv
 <http://www.scorpiondata.com> 

\[Redigerat av Peter_B den 24 sep 2000\]

Permalänk: https://www.webforum.nu/p/341150

## #6 — stevenet, 2000-09-24T12:55Z

Skälet till att jag lade till Content-type: text/html, var att det första exemplet inte fungerade samt att det fungerar och används på min server. 
Dessutom fungerar det bäst, på min server, med två \\n.

Annars håller jag med Peter, prova på!

Permalänk: https://www.webforum.nu/p/341151

## #7 — Peter_B, 2000-09-24T21:02Z

tja, jag har bara provat det med apache och linux, men om det funkar på andra sätt så har iaf jag lärt mig nått.. fast bra skummt va det isf :)

Permalänk: https://www.webforum.nu/p/341152

## #8 — Hansen, 2000-09-25T06:32Z

Hej!
Det ska ju funka på alla browsers som följer standarden.

Här kommer ett utdrag från rfc2616 Hypertext Transfer Protocol - HTTP/1.1 @ <http://www.faqs.org/rfcs/rfc2616.html> 

> 14\.30 Location
>
>    The Location response-header field is used to redirect the recipient
>    to a location other than the Request-URI for completion of the
>    request or identification of a new resource. For 201 (Created)
>    responses, the Location is that of the new resource which was created
>    by the request. For 3xx responses, the location SHOULD indicate the
>    server's preferred URI for automatic redirection to the resource. The
>    field value consists of a single absolute URI.
>
>        Location       = "Location" ":" absoluteURI
>
>    An example is:
>
>        Location: <http://www.w3.org/pub/WWW/People.html> 
>
>       Note: The Content-Location header field (section 14.14) differs
>       from Location in that the Content-Location identifies the original
>       location of the entity enclosed in the request. It is therefore
>       possible for a response to contain header fields for both Location
>       and Content-Location. Also see section 13.10 for cache
>       requirements of some methods.

//Hansen

Permalänk: https://www.webforum.nu/p/341153

---

Tråden på webben: https://www.webforum.nu/amne/asp/19177-redirectat
