简体   繁体   中英

How to go to sub-directory with relative URI

Sorry if it so basic but I could not find the answer by searching.

If we are in the page http://www.example.com/a-dir-without-trailing-slash how we can reach the sub-directory http://www.example.com/a-dir-without-trailing-slash/pic using relative URI? (we do not know the current directory name(ie a-dir-without-trailing-slash )

Some more explanation:

a-dir-without-trailing-slash is the name of an article in the website. It is not an actual directory nor an actual file name. Now, I want to get the pictures that are used in this article by addresses like:

http://www.example.com/a-dir-without-trailing-slash/pic/1

http://www.example.com/a-dir-without-trailing-slash/pic/2

,...

and in the webpage html, I would refer to them with something similar to:

 <img src="pic/1" />

If the original article address was in the form of http://www.example.com/a-dir-with-trailing-slash/ , the above example would work finely. I want to know if is it possible to get a relative URI with current article addresses (without trailing slash)?

Thank you very much

I suppose you want to avoid hard coding "slugs" in the content so that they can be stored and manipulated independent of each other.

One solution is to use the base tag which allows you to specify the prefix that is added to relative URLs instead of typing them all over the place.

  1. Make sure that your website uses absolute URLs where necessary.
  2. Modify your CMS to "generate" and place the following tag inside the head section that contains trailing slash:
<base href="/a-dir-without-trailing-slash/">
  1. Then you can use relative URLs inside the content, for example:
<img src="pic/1">
<!-- http://www.example.com/a-dir-without-trailing-slash.html/pic/1 -->

You need server side scripting to add the filename to urls (or may be just one '> tag in the head). – Salman Bounty get.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM