Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In my project functionality is like when i need to set a link to direct to:

/site/sales/sold.php

so the menu.php file link would look like this:

 <ul>
      <li><a href="sales/">Sales</a></li>   
      <li><a href="sold.php">Sold Items</a></li>
    </ul>

it would sometime direct to

/site/sales/sold.php 

and the next moment, it repeats the menu's directory like:

/site/sales/sales/sold.php

so i removed the sales directory, as its directing there by itself, worked for a little while and now it directs to

/site/sold.php

which does not exist so it ends up with a 404.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
143 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you are on a page sales/ and link to a page sales, the link will result in sales/sales/ – that is the defined behavior.

The default method to avoid that is to specify a base URL via the HTML <base> tag. There is no PHP, JS or CSS involved here – just good ol' HTML 2.0.

<base href="http://www.example.com/site/">

Using this in your pages head, will define the given URL as base for all links on the page, thus a link like sales/ will actually result in http://www.example.com/site/sales/ when clicked.

See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...