Skip to content Skip to sidebar Skip to footer

Relative Links On Pages Without Trailing Slash

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 ht

Solution 1:

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><basehref="/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.

Solution 2:

a href="./content"

you can try this

Solution 3:

Relative paths work relative to the folders in which the html page is located.

So for instance, if you are within domain.com's public_html, and there is a folder called page. Then your link whatever is going to link to domain.com/page/content.

Similarly, if you were on a route like domain.com/page where you your link was featured as content. Clicking that link would take you to domain/page/content. Further reading: http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/

<a href="linkhere.html">ClickMe</a>
This link points to a filename, with no path provided. This means that linkhere.html is located in the same folder as the page where this link appears.
If both files were located in the root directory of the Website http://www.website.com,
 the actual website address the user would be taken to is http://www.website.com/linkhere.html. If both files were located in a subfolder of the root directory called files, the user would be taken to http://www.website.com/files/linkhere.html.How about another example?Let's say we our http://www.website.com domain had a subfolder called pictures. Inside the pictures folder is a file called pictures.html. The full path to this page would be:"http://www.website.com/pictures/pictures.html"Still with us?Good. Let's say in this pictures.html file, we have a link:
<a href="morepictures.html">MorePictures</a>
If someone clicked that, wheredo you think it would take them?If you said http://www.website.com/pictures/morepictures.html, you'd be right! You probably know why it would take them there: 
because both files are saved in the pictures subfolder.

Post a Comment for "Relative Links On Pages Without Trailing Slash"