You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Antti Linno <al...@all.ee> on 2001/04/08 14:56:58 UTC

Redirect with anchors.

Hallo.

I need to know how to use redirect so, that the anchors have effect. Tried
to use apache redirect

use Apache;
use Apache::Constants qw(REDIRECT);

$req_rec->header_out("Location" => "intranet.html?action=show#anchor_name");
$req_rec->status(REDIRECT);

The html has such tag, but redirect shows no effect. Tried with simple
html link and it worked. 

Any ideas how to get to some anchor in the middle of the page?

Greetings,
	Antti




Re: Redirect with anchors.

Posted by Gerd Kortemeyer <ko...@lite.msu.edu>.
1) First suggestion:

Try

 $req_rec->header_out("Location" => "intranet.html#anchor_name?action=show");

Seems like that is the order that at least Netscape puts GET-parms and anchors
in.

2) If the above does not work, try

$req_rec->header_out("Location" =>
"intranet.html?action=show&anchor=anchor_name");

Then have the handler for intranet.html spit out a line of JavaScript:

<script>document.location.hash='anchor_name';</script>

... works amazingly well. No need for anybody to tell me just how yucky this is.

3) Alternatively, try to find out if it is not Apache that somehow eats your "#"
- you might have to escape that.

- Gerd.


Elizabeth Mattijsen wrote:

> At 02:56 PM 4/8/01 +0200, Antti Linno wrote:
> >$req_rec->header_out("Location" => "intranet.html?action=show#anchor_name");
>
> I think you should provide the _complete_ URL, including the http://server
> part.  Some browser do not handle incomplete URL's like this in a redirect
> correctly.  Please someone correct me if I'm wrong here...
>
> >The html has such tag, but redirect shows no effect. Tried with simple
> >html link and it worked.
> >Any ideas how to get to some anchor in the middle of the page?
>
> Some browsers support the ?action#anchor syntax.  Some don't (particularly
> not too recent MSIE's).  If you really want to reliably do this, you should
> hide your parameter in the URL and use a RewriteRule or a mod_perl handler
> to extract the parameter, e.g. instead of
> "intranet.html?action=show#anchor_name" use a URL in the form
> "/show/intranet.html#anchor".
>
> Hope this helps...
>
> Elizabeth Mattijsen

Re: Redirect with anchors.

Posted by Andrew Ho <an...@tellme.com>.
Hello,

AL>$req_rec->header_out("Location" => "intranet.html?action=show#anchor_name");

EM>I think you should provide the _complete_ URL, including the
EM>http://server part.  Some browser do not handle incomplete URL's like
EM>this in a redirect correctly.  Please someone correct me if I'm wrong
EM>here...

Actually, there was a long thread on this a while back on this mailing
list. Apache will intercept any URL without http:// and tack on the right
hostname. You can verify this by doing the above code and telnetting to
port 80 manually. So it doesn't matter whether you add the hostname or not
(although I like to, because I like to rely as little as possible on magic
API behavior).

EM>Some browsers support the ?action#anchor syntax.  Some don't
EM>(particularly not too recent MSIE's).  If you really want to reliably do
EM>this, you should hide your parameter in the URL and use a RewriteRule or
EM>a mod_perl handler to extract the parameter, e.g. instead of
EM>"intranet.html?action=show#anchor_name" use a URL in the form
EM>"/show/intranet.html#anchor".

Actually, the syntax ?foo=bar#anchor is correct according to the URI
specification--the anchor always goes last. My version of MSIE barfs on
this, but Netscape picks it up correctly. The moral is, that this is a
very badly understood and poorly implemented form of a URI, so your advice
on hiding either the query arguments or the anchor is exactly correct.

Humbly,

Andrew

----------------------------------------------------------------------
Andrew Ho               http://www.tellme.com/       andrew@tellme.com
Engineer                   info@tellme.com          Voice 650-930-9062
Tellme Networks, Inc.       1-800-555-TELL            Fax 650-930-9101
----------------------------------------------------------------------


Re: Redirect with anchors.

Posted by Elizabeth Mattijsen <li...@dijkmat.nl>.
At 02:56 PM 4/8/01 +0200, Antti Linno wrote:
>$req_rec->header_out("Location" => "intranet.html?action=show#anchor_name");

I think you should provide the _complete_ URL, including the http://server
part.  Some browser do not handle incomplete URL's like this in a redirect 
correctly.  Please someone correct me if I'm wrong here...


>The html has such tag, but redirect shows no effect. Tried with simple
>html link and it worked.
>Any ideas how to get to some anchor in the middle of the page?

Some browsers support the ?action#anchor syntax.  Some don't (particularly 
not too recent MSIE's).  If you really want to reliably do this, you should 
hide your parameter in the URL and use a RewriteRule or a mod_perl handler 
to extract the parameter, e.g. instead of 
"intranet.html?action=show#anchor_name" use a URL in the form 
"/show/intranet.html#anchor".


Hope this helps...


Elizabeth Mattijsen