468,119 Members | 1,804 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,119 developers. It's quick & easy.

anchors

To anyone who can help me, you have my thanks in advance.

I am implementing a "301 Moved Permanently" redirect in my website due to a
change of our domain names. Unfortunately, I am having a problem with
reconstructing the target "Location" http header because I'm missing just
one thing.

My links look as follows:

http://www.oldurl.com/beanie.php#thr...=false&demt=43

This I need to change to the following:

http://www.newurl.org/beanie.php#thr...=false&demt=43

As you can see, it's no BIG deal. All I need to change is the start and all
the rest can stay the same. So I need to create the new URL as a string so I
can call the following:

header("HTTP/1.1 301 Moved Permanently");
header($locationstring);
exit;

That's all.

First, I recreate the "server name" with the following two lines of code:

$oldurl = $_SERVER['HTTP_HOST'];
$newurl = str_replace("oldurl.com", "newurl.org", $oldurl);

Next, I can recreate the file name ("beanie.php") with the following line of
code:

$locationstring = ("Location: http://".$newurl.$_SERVER['PHP_SELF']);

Now I've got http://www.newurl.org/beanie.php.

The two GET vars "register" and "demt" I can access with

$registercode = $HTTP_GET_VARS["register"];
$articlecode = $HTTP_GET_VARS["demt"];

But how do I get the anchor!?!?!?!? How do I know if there was one and if so
what it was (the #three bit above).

Many thanks,

Ben.

Jul 17 '05 #1
7 1987
"Ben Wilson" <pl******@spam.com> wrote in
news:40***********************@news.skynet.be:
I am implementing a "301 Moved Permanently" redirect in my website due
to a change of our domain names. Unfortunately, I am having a problem
with reconstructing the target "Location" http header because I'm
missing just one thing.

My links look as follows:

http://www.oldurl.com/beanie.php#thr...=false&demt=43

This I need to change to the following:

http://www.newurl.org/beanie.php#thr...=false&demt=43
[snip]
But how do I get the anchor!?!?!?!? How do I know if there was one and
if so what it was (the #three bit above).


Unfortunately, you can't. Browsers don't send out fragment identifiers
when they make requests. If someone follows your old link, the browser is
going to ask the server for "beanie.php?register=false&demt=43" and, once
it gets a response, go looking for an id or named anchor called "three" in
the response.
Jul 17 '05 #2

"Eric Bohlman" <eb******@earthlink.net> wrote in message
news:Xn*******************************@130.133.1.4 ...
"Ben Wilson" <pl******@spam.com> wrote in
news:40***********************@news.skynet.be:
I am implementing a "301 Moved Permanently" redirect in my website due
to a change of our domain names. Unfortunately, I am having a problem
with reconstructing the target "Location" http header because I'm
missing just one thing.

My links look as follows:

http://www.oldurl.com/beanie.php#thr...=false&demt=43

This I need to change to the following:

http://www.newurl.org/beanie.php#thr...=false&demt=43


[snip]
But how do I get the anchor!?!?!?!? How do I know if there was one and
if so what it was (the #three bit above).


Unfortunately, you can't. Browsers don't send out fragment identifiers
when they make requests. If someone follows your old link, the browser is
going to ask the server for "beanie.php?register=false&demt=43" and, once
it gets a response, go looking for an id or named anchor called "three" in
the response.

Excellent! Then I don't even have to bother returning it! I can just forget
about it, for the browser will pick it up automatically! This exceeds my
expectations by far, by very far. In fact, it couldn't get any better. Thank
you,

Ben.


Jul 17 '05 #3
Ben Wilson wrote:

[ ... ]
http://www.oldurl.com/beanie.php#thr...=false&demt=43

This I need to change to the following:

http://www.newurl.org/beanie.php#thr...=false&demt=43
Cool, a dot com becomes a dot org; and "beanie"'s got me intrigued
too. But I can't access either. If those are examples, will you be
kind enough to post the actual URIs, please?

It's better to use the reserved TLD ".example" for examples (RFC2606).

[ ... ]
The two GET vars "register" and "demt"


Those URIs have no query components: there are no "GET vars". Did you
just write them wrongly here?

--
Jock
Jul 17 '05 #4

"John Dunlop" <us*********@john.dunlop.name> wrote in message
news:MP************************@News.Individual.NE T...

Cool, a dot com becomes a dot org; and "beanie"'s got me intrigued
too. But I can't access either. If those are examples, will you be
kind enough to post the actual URIs, please?

It's better to use the reserved TLD ".example" for examples (RFC2606).
Dear John:

Thank you for bringing RFC2606 to my attention. I am pleased to provide you
with the corrected URIs which I hope you will find less confusing:

http://www.oldhost.invalid/foo.php#t...=false&demt=43

http://www.newhost.invalid/foo.php#t...=false&demt=43

The two GET vars "register" and "demt"


Those URIs have no query components: there are no "GET vars". Did you
just write them wrongly here?

I'm sorry, I thought "register" was a GET var here equal to "false" and that
"demt" was a GET var equal to "43". Euhm, am I misunderstanding something?


--
Jock

Jul 17 '05 #5
"Ben Wilson" <pl******@spam.com> wrote in message
news:40***********************@news.skynet.be...

"John Dunlop" <us*********@john.dunlop.name> wrote in message
news:MP************************@News.Individual.NE T...

Cool, a dot com becomes a dot org; and "beanie"'s got me intrigued
too. But I can't access either. If those are examples, will you be
kind enough to post the actual URIs, please?

It's better to use the reserved TLD ".example" for examples (RFC2606).
Dear John:

Thank you for bringing RFC2606 to my attention. I am pleased to provide

you with the corrected URIs which I hope you will find less confusing:

http://www.oldhost.invalid/foo.php#t...=false&demt=43

http://www.newhost.invalid/foo.php#t...=false&demt=43
I can't stand the suspense... You don't have a query component because
you've put the anchor ahead of what you seem to think is the query string.
If you moved the anchor to the end where it belongs, you'll have a query
string (set of query parameters).
The two GET vars "register" and "demt"


Those URIs have no query components: there are no "GET vars". Did you
just write them wrongly here?

I'm sorry, I thought "register" was a GET var here equal to "false" and

that "demt" was a GET var equal to "43". Euhm, am I misunderstanding something?


yes... or so it seems.

- Virgil
Jul 17 '05 #6
Ben Wilson wrote:
http://www.newhost.invalid/foo.php#t...=false&demt=43
[ ... ]
I'm sorry,
No need to apologise!
I thought "register" was a GET var here equal to "false" and that
"demt" was a GET var equal to "43".
There is no query component here, no "GET vars" if you like, because
everything after the "#" is the fragment identifier and technically
not part of the URI. Besides, as Eric says, it's not even *given* to
the server; the user-agent keeps it and applies it to the retrieved
resource; as for text/html bodies, which presumably yours is,

| ... the fragment identifier designates the correspondingly named
| element; any element may be named with the "id" attribute, and A,
| APPLET, FRAME, IFRAME, IMG and MAP elements may be named with a
| "name" attribute.

RFC2854, "The 'text/html' Media Type",
http://www.ietf.org/rfc/rfc2854.txt

As Virgil Green has said, fix this by moving "#three" to the end:

http://www.newhost.invalid/foo.php?r...&demt=43#three

The query component is now "register=false&demt=43" and the fragment
identifier is "three".
Euhm, am I misunderstanding something?


I didn't elaborate on my apology for an explanation before because I
thought you just muddled up the parts of the URI references in your
article and wouldn't have appreciated it. Perhaps I was mistaken.

I'd still like to see the actual website! ;-)

--
Jock
Jul 17 '05 #7

"John Dunlop" wrote:
http://www.newhost.invalid/foo.php#t...=false&demt=43
[ ... ]
There is no query component here, no "GET vars" if you like, because
everything after the "#" is the fragment identifier and technically
not part of the URI. Besides, as Eric says, it's not even *given* to
the server; the user-agent keeps it and applies it to the retrieved
resource; as for text/html bodies, which presumably yours is,

| ... the fragment identifier designates the correspondingly named
| element; any element may be named with the "id" attribute, and A,
| APPLET, FRAME, IFRAME, IMG and MAP elements may be named with a
| "name" attribute.


Thank you (and Virgil) for your help. I understand what you are referring
to. The hypothetical URL I've taken here as an example is misformed.
Actually this is because there are no pages on the site that combine both
get vars and anchors. I realised for the pages that used get vars I could
reproduce the get vars by accessing the array, but for the pages that used
anchors I could not reproduce the anchors. I had never actually had to
implement both features at once.

I don't check out newsgroups often but I am surprised by everyone's interest
to see the website I'm working on. (Yes, the pages do have the extension of
asp but this is because we made a migration from asp to php and we haven't
gotten round to changing the extensions. That will be a next project.)

I will keep you in suspense no longer. An example of a page from our site
that uses getvars is

http://www.falconsoft.be/newsq.asp?article=325C5

An example of a page from our site that uses anchors is

http://www.falconsoft.be/careers!main.asp#02

All the best,

Ben.


I'd still like to see the actual website! ;-)

--
Jock

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by mlv2312 | last post: by
1 post views Thread by mlv2312 | last post: by
2 posts views Thread by learner | last post: by
21 posts views Thread by adrian suri | last post: by
12 posts views Thread by Rich | last post: by
3 posts views Thread by windandwaves | last post: by
13 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.