John Smith
John Smith

Reputation: 359

How should I create a link to a directory within the same subdomain?

I currently have an index file saved under a url of the form subdomain.domain.com/directory1. Within directory 1, I have another directory called directory2. To access the index page for directory2 I have used a link of the form <a href="/directory2">Link</a>.

I would have expected this link to lead the user to the page subdomain.domain.com/directory1/directory2 when clicked, but instead it directs to subdomain.domain.com/directory2.

Why does this happen?

Upvotes: 0

Views: 38

Answers (1)

CarlosCarucce
CarlosCarucce

Reputation: 3569

You should use the complete path:

<a href="/directory1/directory2">Link</a>

That happens because you're using a relative url.

Edit~:

For instance: What is relative URL?

Lets assume your script (index.html in this example) is being executed at http://example.com/ with this folder structure:

index.html
uploads/
   - img.jpg
images/
   - banners/
       - banner1.jpg
       - banner2.jpg

If you want to create a link to 'uploads' folder, all you have to do is

<a href="uploads/">go to uploads</a>

That is because they are in the same structure level.

In the other hand, if you want to link one of the banners, you'd have to "navigate" trough images and then banners. It means that relative to your script, there is images/banner/,

Upvotes: 1

Related Questions