Forum Moderators: phranque

Message Too Old, No Replies

Getting anchor from URL

.htaccess

         

Birdman

12:57 pm on Nov 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

I am trying to get the anchor(index.html#123) from a URL and add it into my rewrite as a var.

Example:

site.com/index.php#abc123

would rewrite to...

site.com/script.php?anchor=abc123

I am sure this is simple, but I can't get it.

I've tried:

rewritecond %{QUERY_STRING} ^#(.*)$
rewriterule ^index.php(.*)$ /index.php?anchor=%1

and also without the # in the cond line.

The cond pattern matches when I leave out the #, but it also leaves the anchor var empty. I tested it by printing the querystring with php.

How can I get the value of the anchor in the url into a variable, so I can acces it in the script.

Thanks,
Birdman

Yidaki

1:05 pm on Nov 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure but what about that:

RewriteRule ^index.php#(.*)$ /index.php?anchor=$1 [L]

killroy

1:08 pm on Nov 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is impossible. the bit after the hash NEVER get's send to the server. The browser simply strips it out, andthen uses it to jump to the anchor once the page is loaded. I'm afraid you'll have to use PATH_INFO or QUERY_STRING instead.

SN

Yidaki

1:17 pm on Nov 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What i wrote was nonsense. I fear it's impossible. But i'm testing ...

Birdman

1:20 pm on Nov 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the replies. I cannot get the anchor to show using any of the $_SERVER variables. This is a pain!

Birdman

1:22 pm on Nov 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is weird is that it the rewritecond matches for QUERY_STRING, yet there is none except for the anchor.

Yidaki

2:48 pm on Nov 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No way. htaccess always ignores the anchor.

What's also weird is that using php alone not even this returns the anchor for index.php#anchor:

<?php
$parsed = parse_url( $REQUEST_URI );
print $parsed['fragment'];
?>

Shouldn't this print "anchor"?

It doesn't. $parsed['fragment'] is empty.

JaaayyyyyDeeeeeee ...

jdMorgan

3:46 pm on Nov 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yidaki,

Now, don't go hollerin' fer me... I ain't never tried this, and I know better'n to *guess* about mod_rewrite stuff - leastways in public and when everbody's sober... :)

I've never seen a local anchor in anything but the {HTTP_REFERER} var, if I recall... This is consistent with what killroy said in post#3.

Why doncha try one of them there fancy php variable-dumpin' scrips -- You know, the ones what print out the whole world to the page, and see if there's any hint of a pound-sign-URL that the server kin git aholt of in there... I reckon not, but it's worth a shot.

Back on the tractor - no, not kidding...
Jim

killroy

4:20 pm on Nov 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You wont find it. Use a packet sniffer, it's never even leaving the browser, I'm talling ya! Do ye hear me?

SN

Yidaki

4:25 pm on Nov 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, makes sense, killroy. Anchor's are on page features that don't go to the server. But i wonder what the php "fragment" token then means ...

Thanks for your tractor pause, jd. I gonna try the referer but i doubt it'll wok.

Birdman

9:20 pm on Nov 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, that is not good news :(

The reason I needed to grab the value is because the link points to a page with multiple listings and the client wants an ad to appear directly under the listing that the pages jumps to. I think it's a great idea but my original job was to get the urls friendly.

Any ideas?

Birdman

10:01 pm on Nov 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe JavaScript is the way to proceed. It's Adsense, which uses JS, so I don't see any downside. Does that sound kosher?

Birdman

closed

5:54 am on Nov 9, 2003 (gmt 0)

10+ Year Member



I was just looking through my log files today and I found this:

"GET /image.gif HTTP/1.1" 200 1825 "http://www.mydomain.com/somepage.html#acronym" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020830"

It looks like a legitimate user, too. It's just strange seeing an anchor in my logs.