Permalinks - Absolute URLs and Good Practise
2 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: August 8, 2013 (RSS)
By Perchpole - August 8, 2013
Hello, All -
I've managed to get Permalinks working fairly well and I'm increasingly pleased with the results. There are a couple of caveats, however, most notably the need to use absolute URLs almost everywhere. This is a bit of a pain as most web design work encourages the use of relative URLs. However I'm perfectly happy to employ a different strategy. I just wondered what would be the best way of going about things?
All I need to do is drop in a piece of code before each URL. For example, typically I would reference a CSS file along the lines of:
href="css/style.css"
I could change that to:
href="<?php echo $mySettings['siteURL'] ?>/css/style.css"
or even:
href="<?php echo $_SERVER['HTTP_HOST'] ?>/css/style.css"
or perhaps there's a CMSB "super global" I could use....?
In any event, which method would be best?
:0)
Perch
By gregThomas - August 8, 2013
Hi Perch,
What about using the absolute path instead of a full URL?
href="/css/style.css"
The proceeding slash tells the browser that it needs to look in the base directory of the site, so this above example would grab http://example.com/css/style.css regardless of what directory you're currently in.
This also has the benefit that the correct protocol (http/https) will always be used when the browser gets the file.
Thanks!
Greg
PHP Programmer - interactivetools.com