Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative links on pages without trailing slash

Tags:

html

On pages that has no trailing slashes in their URL, is there any way to use relative links that will keep the page in the url?

For example, the link

a href="content"

on the page

http://www.domain.com/page/

will link to:

http://www.domain.com/page/content

But the same link on the page: (notice the missing slash)

http://www.domain.com/page

will link to:

http://www.domain.com/content

Since my website has no trailing slash (second example), I can't use relative links and must use the full path (a href="/page/content").

like image 656
Ronen Teva Avatar asked Dec 01 '25 01:12

Ronen Teva


1 Answers

Other than including a trailing slash in the link in the first place, or redirecting from paths missing a trailing slash, you may also set the base tag such that it always includes a trailing slash and the current path.

<head>
  <base href="/page/" target="_self">
</head>

Then relative links should work as anticipated as long as the browser supports this. It is also possible to fully qualify the path. You may not be able to set this dynamically with javascript.

like image 149
user2905353 Avatar answered Dec 03 '25 14:12

user2905353



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!