1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How do I force full URLs?

Discussion in 'XenForo Development Discussions' started by Jaxel, Dec 14, 2010.

  1. Jaxel

    Jaxel Well-Known Member

  2. Jaxel

    Jaxel Well-Known Member

    Figured it out:
    Code:
    $this->canonicalizeRequestUrl(XenForo_Link::buildPublicLink('media', $media));
    Some warnings though... normally you want to use 'full:media' instead of just 'media' when building public links. This way it generates a full absolute URL, instead of just a relative URL. However, when you try to use 'full:' while building a canonical URL through XenForo's system, it creates a redirect loop.

    You can also add ", array('page' => $page)" to the end of your buildPublicLink functions. Supposedly this includes query information into the canonical URL. However, I have removed this section and it still maintains the page query... so I dont think it's needed.
     
  3. Jeremy

    Jeremy XenForo Moderator Staff Member

    Try:
    PHP:
    $this->canonicalizeRequestUrl(XenForo_Link::buildPublicLink('media'$media, array()))
    I haven't looked at any of your code for proper buildPublicLink() setup, but I think this will work. Only thing I could think of.

    Edit: I see you were working just as hard as I was!
     
  4. Jaxel

    Jaxel Well-Known Member

  5. Jeremy

    Jeremy XenForo Moderator Staff Member

    Oh yes I do. ;) I like that atmosphere. It was a fun read to read both the controller and about 4 other XF files... :D
     
  6. Shadab

    Shadab Well-Known Member

    When in a controller, you can also build links using the _buildLink() method.
    This was introduced in Beta 4.

    PHP:
    $this->canonicalizeRequestUrl($this->_buildLink('hello'));
     
    Jeremy likes this.
  7. Mike

    Mike XenForo Developer Staff Member

    I'm curious as to why you'd normally want "full"? It's primarily used in breadcrumbs for metadata reasons, and occasionally it's used where there are base tag issues. Normally, almost all of your links would be relative. ("Canonical" is a different type of link, though it's probably not applicable here - if anything, it'd be applicable everywhere.)

    True, though the only reason that function appeared was for canonicalizePageNumber()... and, err, it's not even using it? Oops!
     
    Jeremy likes this.
  8. Jaxel

    Jaxel Well-Known Member

    Why would you ever NOT want to use full links? Full links would get sorted in search engines better, wouldn't they?
     
  9. Mike

    Mike XenForo Developer Staff Member

    They shouldn't make a difference for SEs. Very few links in XF are "full" links.
     
  10. Jaxel

    Jaxel Well-Known Member

    Hmm... then is there a realistic reason of why you wouldn't want to use full links?

    I can easily remove the "full:" references in my mods... I just want to know if there is a good reason to do so.
     
  11. Mike

    Mike XenForo Developer Staff Member

    I could just as easily ask the opposite question. :)

    They really provide no benefit in the average case - thought there are some edge cases where you need them. But on the whole, they're just redoing the work of the base tag. If anything, it's just unnecessary characters.
     

Share This Page