I've got a website with includes the following directive in the HEAD section:

<base href="https://example.com" />

Now, I want to create internal links to sections within the page 'https://foo.com/product/name-of-the-product'

<a href="#photos">Photos</a>

But, instead of linking to 'https://foo.com/product/name-of-the-product#photos', it links to 'https://foo.com/#photos'.

Any tip to fix this? Thank you.

  • 1
    Can you remove the base href? Technically it isn't a problem. That is how base href is supposed to work. It sounds like you don't actually want a base href. – Stephen Ostermiller Dec 3 '20 at 13:52

I can't recall ever having tried it but I'm oddly certain you can use

"/name-of-the-product#photos" instead of just #photos

Alternatively, as @StephenOstermiller says, drop the "base" statement from the header (you can likely replace its functionality with RewriteRules at the server config level or similar if you are trying to create a canonical URL.

  • Can you imbed php code in your page? If so you can use php to programmatically deduce name-of-product", eg <?php echo $_SERVER['REQUEST_URI'] ?> – davidgo Dec 3 '20 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.