Results 1 to 5 of 5

Thread: Output absolute paths

  1. #1

    Default Output absolute paths

    Hello,

    Is there a way to output absolute paths in contao ? I mean getting rid of the <base> tag and have my urls written like "http://ww.domain-name.com/../tl_files/..." instead of having a relative path like "tl_files/..." ?

    I have to do this because i'm experiencing problems with domain to subdomain redirection.

    Can anyone help ?

    Thanks
    Utilisateur de Contao depuis 2008

  2. #2
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: Output absolute paths

    One thing you can do is use the "generateFrontendUrl" hook. This hook is called any time a URL is generated by the system (of course if you have any URLs that are hard-coded -- maybe in a WYSIWYG box or something, you'll have to change them manually).

    http://www.contao.org/en/hooks.html#generateFrontendUrl

    It would look something like this:

    /system/modules/customurls/config/config.php:
    Code:
    $GLOBALS['TL_HOOKS']['generateFrontendUrl'][] = array('CustomUrls', 'forceAbsolute');

    /system/modules/customurls/CustomUrls.php:
    Code:
    class CustomUrls extends Frontend
    {
    
    public function forceAbsolute($arrRow, $strParams, $strUrl)
    {
    return $this->Environment->url . '/' . $strUrl; // I forget if the '/' is needed...
    }
    
    }
    That's an oversimplified solution -- you'll probably want to add some extra checks to $strUrl first (for example, to make sure it isn't already absolute). But it's the gist of what you want.

    For links in TinyMCE, there's an option to force those to be absolute too:
    http://www.tinymce.com/wiki.php/Configu ... ative_urls
    http://www.tinymce.com/wiki.php/Configu ... nvert_urls (just in case).
    Brian

  3. #3

    Default Re: Output absolute paths

    Hi medianomaly,

    thanks for your reply.
    What is customurl ? where doyou find it ?

    thanks
    Utilisateur de Contao depuis 2008

  4. #4

    Default Re: Output absolute paths

    So far, i have filled the fields in "DNS settings" for my images folder, plugins folder and scripts folder, but it doesn't include the modules folder.

    Your scripts works, but only on href attributes, not on src attributes
    Utilisateur de Contao depuis 2008

  5. #5
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: Output absolute paths

    Hmm... If you need images too, I'm not sure what the best way is to do that.

    There's another hook (getImage), that works similar to the one used in the code I posted, but I don't know if that would work. Images that don't need resizing might not call it (not sure though).
    http://www.contao.org/en/hooks.html#getImage

    Otherwise you may have to do something like add the domain to the paths of all your template code... Maybe someone knows a better way.

    I wonder if you could do this all with .htaccess rules? Like rewrite all requests to force the full absolute path... If that's possible it would be even better because your paths could stay how they are now (the redirect would be invisible). Unfortunately I'm no expert on this part.
    Brian

Bookmarks

Posting Permissions

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