Mobile app version of vmapp.org
Login or Join
Bryan171

: Can missing anchors be logged? If I have a broken link it gets logged with a 404. If I have a link to an anchor and the anchor is missing, I don't get an entry in the log. How can I

@Bryan171

Posted in: #Anchor #Apache #Html #Logging

If I have a broken link it gets logged with a 404. If I have a link to an anchor and the anchor is missing, I don't get an entry in the log. How can I find those broken anchor links, especially if the traffic is coming from a referrer? Is there a way to configure the logging to capture this information?

HTTP Server: Apache 2

10.04% popularity Vote Up Vote Down


Login to follow query

More posts by @Bryan171

4 Comments

Sorted by latest first Latest Oldest Best

 

@Shakeerah822

As others have said, page anchors are something that the browser operates on rather than the web server.

You could use some code to pass the anchor info on to your Analytics program. For example you could extract the location.hash value and pass it to Google Analytics as a custom variable.

More usefully you could run code that checks the page html for an anchor that corresponds to the value of location.hash and if it's missing triggers a GA event. That would then give you a GA report on broken page anchor links as users click on them.

10% popularity Vote Up Vote Down


 

@RJPawlick198

It is impossible to configure logging of the #fragment portion of the URL because your web server never sees it. From RFC3986


the fragment identifier is separated from the rest of the URI prior to a dereference, and thus the identifying information within the fragment itself is dereferenced solely by the user agent, regardless of the URI scheme. Although this separate handling is often perceived to be a loss of information, particularly for accurate redirection of references as resources move over time, it also serves to prevent information providers from denying reference authors the right to refer to information within a resource selectively. Indirect referencing also provides additional flexibility and extensibility to systems that use URIs, as new media types are easier to define and deploy than new schemes of identification.


What this means is that the web browser basically strips off the anchor part of the URI before sending it to the web server. The HTTP protocol doesn't even deal with fragments because of this; they're never sent over the wire.

Fragments are available to JavaScript (because it's client-side) as part of the location.href property. Once obtaining the fragment name, you can confirm that it is valid by searching the document.anchors[] array elements' name property for that value.

Once you've done this, it can be logged using AJAX or, as pelms notes, passed to Google Analytics or similar services.

10% popularity Vote Up Vote Down


 

@Berryessa370

CSE HTML Validator checks for missing anchors... for a price.

See www.htmlvalidator.com/htmlval/whycseisbetter.html

10% popularity Vote Up Vote Down


 

@Rivera981

I don't think its possible to see this in Apache's logs. If a file is requested and served, that pretty much ends Apache's involvement (or any other server). Finding and positioning to the anchor is something the browser does. By the time your browser gets to locating the anchor, the connection to the server is already closed.

A good link checker should pick that up, but that's a manual process.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme