Page 1 of 3 123 LastLast
Results 1 to 10 of 21
  1. #1
    Join Date
    Jun 2005
    Location
    Kelowna, BC Canada
    Posts
    1,075
    Plugin Contributions
    6

    Default Is <base href tag necessary?

    I never knew "base" has such a sordid history.

    I was running into weirdness with internal anchor links. Things just weren't behaving nicely at all. I did some research and found suggestions that it is difficult - to say the least - to use them if the <base href= tag is used on the page. The advice that came up several times was to not use the tag, as it just isn't that useful.

    So on a whim I tried it. I just commented out that code. I see no ill effects, but what track am I walking into here? Sure it was there for a reason.

  2. #2
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Is <base href tag necessary?

    Quote Originally Posted by s_mack View Post
    I never knew "base" has such a sordid history.

    I was running into weirdness with internal anchor links. Things just weren't behaving nicely at all. I did some research and found suggestions that it is difficult - to say the least - to use them if the <base href= tag is used on the page. The advice that came up several times was to not use the tag, as it just isn't that useful.

    So on a whim I tried it. I just commented out that code. I see no ill effects, but what track am I walking into here? Sure it was there for a reason.
    Without knowing the context this isn't a particularly easy one to answer. However for the sake of discussion lets assume that the HTML in question is something to be sent as email - Eg, an order confirmation.

    If all of the links in the email are absolute, there is no problem.

    If some of the links are relative, and there isn't a base href tag then the email links can't/won't work, because the client software doesn't know what these links are relative *to*.

    In other words, in HTML formatted emails, if relative links are used, then the Base Href must also be used.

    When it comes to webpages on a website, then the relative links on the page are relative to the site they are on, No base href needed (except in very specific circumstances), and as a general rule it is best to NOT use them (at least in my personal opinion).

    So, quick summary...
    HTML formatted Emails. Use relative links *and* base Href, *or* absolute links and no base href needed.
    HTML Webpages - No base href needed.

    Cheers
    RodG

  3. #3
    Join Date
    Jun 2005
    Location
    Kelowna, BC Canada
    Posts
    1,075
    Plugin Contributions
    6

    Default Re: Is <base href tag necessary?

    I was referring to webpages. The default template uses it. The template I purchased uses it. I just didn't know why.

    So thanks.

  4. #4
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,511
    Plugin Contributions
    126

    Default Re: Is <base href tag necessary?

    It's useful for a number of situations. For example, if you move your code to a subdirectory, you just change your includes/configure.php file, and this code means that all properly constructed links (built using zen_href_link) will still work and you won't have to update your code to include "subdirectory_name/".
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  5. #5
    Join Date
    Jun 2005
    Location
    Kelowna, BC Canada
    Posts
    1,075
    Plugin Contributions
    6

    Default Re: Is <base href tag necessary?

    I get that... but then why do my links all work now that I've removed the base tag?

    Right now my site is residing at www.mydomain.com/test

    I plan to move it to www.mydomain.com/shop

    I *ASSUMED* that when I removed the base tag that none of my links or images would work sine (I figured) they would all be relative to a now undefined base... but some stackoverflow post I read said it should work, so I tried it. It works. Why? And if it does work, then why wouldn't it work once I switch directories? I haven't hardcoded "test" into anything.

  6. #6
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default Re: Is <base href tag necessary?

    Did you read the post by rodG??
    Quote Originally Posted by rodG
    So, quick summary...
    HTML formatted Emails. Use relative links *and* base Href, *or* absolute links and no base href needed.
    HTML Webpages - No base href needed.
    Zen-Venom Get Bitten

  7. #7
    Join Date
    Jun 2005
    Location
    Kelowna, BC Canada
    Posts
    1,075
    Plugin Contributions
    6

    Default Re: Is <base href tag necessary?

    Yes (obviously. I responded to it) and then I read the post by swguy. Am I to take it one is implicitly correct and the other talking out his hat? I thought he deserved more respect.

  8. #8
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: Is <base href tag necessary?

    Quote Originally Posted by s_mack View Post
    Yes (obviously. I responded to it) and then I read the post by swguy. Am I to take it one is implicitly correct and the other talking out his hat? I thought he deserved more respect.
    As has been the case in the last couple of posts, the quoted text in this post is not clear about who is being discussed as being implicity correct and who is considered to be talking out his hat.

    The additional information provided by swguy is not incorrect, but mostly from a different perspective. It would appear that swguy is striving to encourage the continued use of zen_href_link as with it or "properly" formatted relative links and as rodg stated, the base href tag would not be needed when the content is accessed from a webpage. But, the code is there because links are not always properly formatted by those that modify the their site and by it being present it adds a level of assistance in maintaining continuity and functionality.

    So the real question is what problem are you trying to solve that seems to imply that the base href tag is getting in the way of things? Ie. what is the reason to remove the <base href tag that is in the includes/templates/YOUR_TEMPLATE/common/html_header.php file?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  9. #9
    Join Date
    Jun 2005
    Location
    Kelowna, BC Canada
    Posts
    1,075
    Plugin Contributions
    6

    Default Re: Is <base href tag necessary?

    anchors. Attempting to use a relative link to a named anchor would take me back to the main index page rather than stay at the one I'm on. I couldn't figure out why then I found a lot of posts stating that named anchors are not really compatible with base href.

    Advice by some (in fact many) is to never use relative urls. Always absolute. I don't quite buy that, as it makes moving a site a nightmare. Others said to just ditch base href and all is good. Unless I'm missing something, that seems to be the case.

  10. #10
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: Is <base href tag necessary?

    Quote Originally Posted by s_mack View Post
    anchors. Attempting to use a relative link to a named anchor would take me back to the main index page rather than stay at the one I'm on. I couldn't figure out why then I found a lot of posts stating that named anchors are not really compatible with base href.

    Advice by some (in fact many) is to never use relative urls. Always absolute. I don't quite buy that, as it makes moving a site a nightmare. Others said to just ditch base href and all is good. Unless I'm missing something, that seems to be the case.
    Well, not sure if I fully invoked anchors or a variation on them, but one of the plugins I pushed Checkbox TextBox Icon Product Checkout, used a variation of the anchor process I thought in order to return back to the same location on the page after making a selection up or down and the page reloading... I don't recall if I had to make the same edit or if I came up with an other functional method. I may have "cheated" and only had the base href not show on specific pages... Not sure...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 
Page 1 of 3 123 LastLast

Similar Threads

  1. base href problem
    By cricles in forum Upgrading from 1.3.x to 1.3.9
    Replies: 3
    Last Post: 20 Jul 2010, 06:34 AM
  2. SSL Problem (Base href???)
    By DaveS in forum General Questions
    Replies: 24
    Last Post: 4 Sep 2009, 06:23 PM
  3. Base HREF https issues
    By mikebackhouse in forum General Questions
    Replies: 38
    Last Post: 27 May 2009, 05:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg