dongnachuang6635 2015-07-10 06:46
浏览 38

是否可以仅将<base>标记用于特定的引用和URL?

Good day! Is it possible to use tag for specific references and URL's only? I encountered a problem wherein there is an error anchor tag and its href attribute. For example, there is a module loans, all the PHP files of that module is located at only one folder, take a look of this:

these are the folders and the website:

htdocs - system - members - loans(loan-app.php, loan-sum.php)

If I'm going to use base tag, I got an error whenever I place an src on tags on my code, so as a solution I wont include the value in the base tag in images and only use in links. Is it possible?

Note: Someone suggested me here that I just need to disable the currently opened module to avoid concatenation of url and error. But I realized it just now that I can't because I have another link that is needed to be enable if I open the another BUT they have the same location because they belong at the same module. Unfortunately it can cause concatenation of url.

Anyway, here is my previous question in related to this :

Anchor HREF, if I click again the anchor the link on the address doubles or it concatenate on the existing link. What's the best way to avoid this?

  • 写回答

1条回答 默认 最新

  • duanmo6937 2015-09-17 14:24
    关注

    The base element is used for relative URLs. If you use a full URL for an a element, img element, link element, etc the base element will simply be ignored. The base element is extremely useful for when you want to test local versus live (as you should always test locally first). You can not choose for the base element to only apply to certain situations unless you want to get in to extremely convoluted JavaScript which I don't recommend.

    Base Element

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

    Relative URLs

    <link href="themes/default/style.css" media="screen" rel="stylesheet" type="text/css" />
    
    <img alt="Example" src="images/test.png" />
    
    <a href="loans/">Loans</a>
    
    <a href="loans/sum/">Loan Sum</a>
    

    Use index.php in the folder loans/sum/[index.php] to create clean URLs if you're not using something such as Apache rewrites.

    Effective URLs

    https://www.example.com/themes/default/style.css

    https://www.example.com/images/test.png

    https://www.example.com/loans/

    https://www.example.com/loans/sums/

    Most people start out with convoluting their setups. You should only have the domain name's root most directory (as demonstrated above) and make all your URLs relative.

    For the base element itself you should use PHP to determine whether the site is local or live and then echo the appropriate path; that way you don't any convoluted setup like needing two separate copies of the site.

    You will want to split your base element's PHP code in to two parts; for the live site the $url2 should only be / and then since you'll naturally have other projects archived and/or in development then for localhost you'll change the path accordingly.

    Base Element PHP - Part 1

    `<?php echo '<base href="'.$url1.$url2.'" />' . "
    ";?>`
    

    Base Element PHP - Part 2

    You'll have to do a little bit of work here but this should open your mind up to other juicy possibilities for down the road to make your life easier plus I don't know all your local directory structures. So explore the $_SERVER array to start putting together the $url1 string and remember to keep it simple.

    <?php echo '<pre>';print_r($_SERVER);echo '</pre>';?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题