0

We were trying to create relative links by using href="Link" or href="./Link"

This works on all browsers, but in Drupal we are running into a problem becasue Drupal removes trailing slash from existing URL.

For example if we are at page or taxonomy term page

domain.com/term1/child1A

and in there have a link such as a href="Link" it will point to domain.com/term1/Link

becasue child1A does not have a trailing slash.

Is there any way to fix this issue. Technically we are not trying to add trailing slashes to all url. Tried setting base URL but that didn't work either. Or maybe I did something wrong.

Any suggestions on a workaround?

Drupal 8.4

1 Answer 1

0

The key to this answere is that the URL needs to end with a slash.

I turns out Redirect modules will remove trailing slashes.

You can disable clean URLs if you want trailing slash. Which is not ideal.

A workaround would be to use this code for particular links:

<p><a href="home" id="relurl" target="_blank" title="This is a relative link!">link</a>

var x = window.location.href; // Current page URL var link = document.getElementById("relurl"); // store the element var curHref = link.getAttribute('href'); // Get HREF paramter link.setAttribute('href', x + "/"+ curHref);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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