: 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
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
More posts by @Bryan171
4 Comments
Sorted by latest first Latest Oldest Best
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.
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.
CSE HTML Validator checks for missing anchors... for a price.
See www.htmlvalidator.com/htmlval/whycseisbetter.html
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.