简体   繁体   中英

Using relative links in Blogger

i am using blogger

when i need to mention a link , in a post of my blog and the link is actually a link of my own blog post , i am mentioning itside < a >tag with

www.my_blog_name.blogspot.in/12/2013/how_to_do.html

if i changed my blog name then the link will be dead ,

So what i want is , i just want mention the link with out my blog name

for example

instead of

www.my_blog_name.blogspot.in/12/2013/how_to_do.html

i need to mention it like

/12/2013/how_to_do.html

so even though if i changed my blog name it will work

if you guys having anyother solution for changing blog name does't affects links inside my posts plz mention it

Blogger has <$BlogURL$> tag

<$BlogURL$> points to the URL of your blog.

Usage: A good value for a "home" link, or the "back to current" link in an archive template, eg

<a href="<$BlogURL$>">home</a>

Can also be used as a base href, to make relative links work in both the main page and in archive pages in a separate directory.

So you can do

<a href="<$BlogURL$>/12/2013/how_to_do.html">Your URL</a>


Blogger makes relative links (links like <a href="archives/archive.html"> are relative, links like <a href="http://www.domain.com/archives/archive.html"> are absolute links) a bit more difficult to manage than usual, because most people keep their archives in a different directory than their main page. If you link to "images/mypic.jpg" in a post, then when that post is archived the link will point to "archives/images/mypic.jpg" and thus not be found. The same thing happens if you put a relative link in your main template, because the archive pages are also created from your main template. Fear not, there are two simple fixes.

Fix one is to use a "base href" tag to tell the browser to start every relative url with the path to your main directory. In your main template, in the <head> section, include the tag <base href="<$BlogURL$>"> . If you have the separate archive index page style of archives, include a base href in the section of your archive template as well. The next time you publish or post & publish, all your relative links will start from the directory where you have your main page, whether they are in that directory, or in your archives directory. Just be sure you remember to change the Blog URL in your settings if you move your blog!

The second fix is to use server-rooted paths rather than relative paths: a server rooted path starts with a slash, and lists all the directories from the root directory of the server. For example, if your main page was www.example.com/index.html and your archives were in www.example.com/archives/archive.html , then a server-rooted link to the archives would be <a href="/archives/archive.html"> , and a server-rooted link to an image in www.example.com/images/ would look like <img src="/images/image.jpg"> . However, if your main page is in www.freehost.com/bunch12/~username/blog/blogger.html , a server-rooted link will start /bunch12/~username/blog/ , and using a base href tag will be a whole lot easier (once you get used to it).

Source

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