Welcome to WebmasterWorld Guest from 18.204.48.40

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Getting anchor from URL

.htaccess

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 8, 2002
posts:2015
votes: 0


Not sure but what about that:

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

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

Senior Member from MT 

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 1, 2003
posts:1843
votes: 0


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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 8, 2002
posts:2015
votes: 0


What i wrote was nonsense. I fear it's impossible. But i'm testing ...
1:20 pm on Nov 1, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


Thanks for the replies. I cannot get the anchor to show using any of the $_SERVER variables. This is a pain!
1:22 pm on Nov 1, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


What is weird is that it the rewritecond matches for QUERY_STRING, yet there is none except for the anchor.
2:48 pm on Nov 1, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 8, 2002
posts:2015
votes: 0


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 ...

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


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

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

Senior Member from MT 

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 1, 2003
posts:1843
votes: 0


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

SN

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 8, 2002
posts:2015
votes: 0


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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


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?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


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

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

Full Member

10+ Year Member

joined:Aug 20, 2003
posts:255
votes: 0


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.