Mobile app version of vmapp.org
Login or Join
Carla537

: Strange named anchor behavior - only working with the hash mark after a trailing slash I have an odd problem. Links to named anchors on a site I'm working on are only working correctly if

@Carla537

Posted in: #Links #NamedAnchor

I have an odd problem. Links to named anchors on a site I'm working on are only working correctly if the pound/hash sign is placed after a trailing slash (e.g. example.com/about/#who), rather than directly after a page name (e.g. example.com/about#who).

What could be causing this? I should note that this is on a site running WordPress, with the WPML translation plugin. I'm not sure if that's causing the problem, though (otherwise I'd ask on the WordPress Answers SE site).

Any suggestions as to what could be causing this strange behavior?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Carla537

1 Comments

Sorted by latest first Latest Oldest Best

 

@Angie530

After some research, it looks like leaving out the trailing slash causes your browser to send out another HTTP request for the file "example.com/about#", instead of an internal link like you'd expect.

Now, I tried this kind of request on an IIS web server and an Apache web server, and both sent me back a 301 redirect to the correct URL, so I think they have some built-in functionality to handle this understandable mistake.

However, I would guess that WordPress/WPML uses Apache's mod_rewrite or something similar to make search engine friendly URLs, so that instead of example.com/about.php?user=tnorthcutt, you get example.com/about/tnorthcutt. This will probably bypass the server's normal corrective behavior. So instead of Apache redirecting you to the appropriate URL, it tries to translate it from a search engine friendly version, and everything goes south from there.

So I guess the moral of the story is to just add in the slash, and avoid the extra HTTP request altogether if possible.

Note: This is kind of wild speculation, and I'm making a lot of assumptions about your setup. Grain of salt required.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme