Change to absolute URLs?

HWS

Well-known member
XenForo currently makes use of URLs relative to forum root. All internal links are automatically build like this by the software:
HTML:
<img src="styles/default/xenforo/someimage.png" />
 
<link rel="stylesheet" href="css.php" />
 
<script src="js/xenforo/xenforo.js">
and so on.

To instruct the browsers to load everything correctly, the following code is always served by XenForo in HTML header:
HTML:
        <base href="http://domain.com/xenforo/" />
        <script>
            var _b = document.getElementsByTagName('base')[0], _bH = "http://domain.com/xenforo/";
            if (_b && _b.href != _bH) _b.href = _bH;
        </script>

However there are several problems with browsers that do not understand that correctly and don't load some files, leading to several problems for our users. This happens mostly with Internet Explorer, but also occasionally with Firefox and Chrome. Users cannot post (if js files are missing), see odd design (if css files are missing) or broken picture links.

There are several posts here, describing such problems. They are hard to debug, because no one knows why and when a browser decides to misinterpret the base URL and it can change at every single load of a forum page.

Since we have activated our web server log to catch 404 errors we regularly get such messages:
Code:
2012/12/31 09:39:12 [error] 34319#0: *5865759 open() "/var/www/domain.com/threads/warum-ist-das-so.785290/styles/default/xenforo/clear.png" failed (2: No such file or directory), client: 90.152.175.249, server: domain.com, request: "GET /threads/warum-ist-das-so.785290/styles/default/xenforo/clear.png HTTP/1.1", host: "domain.com", referrer: "http://domain.com/threads/warum-ist-das-so.785290/"
2012/12/31 09:42:20 [error] 34318#0: *5867982 open() "/var/www/domain.com/conversations/segen.697/styles/default/xenforo/clear.png" failed (2: No such file or directory), client: 90.152.175.249, server: domain.com, request: "GET /conversations/segen.697/styles/default/xenforo/clear.png HTTP/1.1", host: "domain.com", referrer: "http://domain.com/conversations/segen.697/page-3"
2012/12/31 09:43:31 [error] 34322#0: *5868704 open() "/var/www/domain.com/threads/maeuseplage.784632/styles/default/xenforo/avatars/avatar_female_m.png" failed (2: No such file or directory), client: 194.166.216.250, server: domain.com, request: "GET /threads/maeuseplage.784632/styles/default/xenforo/avatars/avatar_female_m.png HTTP/1.1", host: "domain.com", referrer: "http://domain.com/threads/maeuseplage.784632/"
2012/12/31 09:46:48 [error] 34320#0: *5870770 open() "/var/www/domain.com/threads/tindra-duftkerze-ikea.784386/styles/default/xenforo/avatars/avatar_female_m.png" failed (2: No such file or directory), client: 194.166.216.250, server: domain.com, request: "GET /threads/tindra-duftkerze-ikea.784386/styles/default/xenforo/avatars/avatar_female_m.png HTTP/1.1", host: "domain.com", referrer: "http://domain.com/threads/tindra-duftkerze-ikea.784386/"
2012/12/31 09:46:48 [error] 34320#0: *5870772 open() "/var/www/domain.com/threads/tindra-duftkerze-ikea.784386/styles/default/xenforo/avatars/avatar_female_m.png" failed (2: No such file or directory), client: 194.166.216.250, server: domain.com, request: "GET /threads/tindra-duftkerze-ikea.784386/styles/default/xenforo/avatars/avatar_female_m.png HTTP/1.1", host: "domain.com", referrer: "http://domain.com/threads/tindra-duftkerze-ikea.784386/"
2012/12/31 09:46:58 [error] 34320#0: *5870773 open() "/var/www/domain.com/threads/wie-gut-trocknen-eure-geschirrspueler.784727/styles/default/xenforo/avatars/avatar_female_m.png" failed (2: No such file or directory), client: 194.166.216.250, server: domain.com, request: "GET /threads/wie-gut-trocknen-eure-geschirrspueler.784727/styles/default/xenforo/avatars/avatar_female_m.png HTTP/1.1", host: "domain.com", referrer: "http://domain.com/threads/wie-gut-trocknen-eure-geschirrspueler.784727/"
2012/12/31 09:54:34 [error] 34322#0: *5875208 open() "/var/www/domain.com/threads/brechdurchfall-2012.784981/styles/default/xenforo/avatars/avatar_female_m.png" failed (2: No such file or directory), client: 194.166.216.250, server: domain.com, request: "GET /threads/brechdurchfall-2012.784981/styles/default/xenforo/avatars/avatar_female_m.png HTTP/1.1", host: "domain.com", referrer: "http://domain.com/threads/brechdurchfall-2012.784981/"
2012/12/31 09:54:47 [error] 34322#0: *5875220 open() "/var/www/domain.com/threads/reizdarm.784296/styles/default/xenforo/avatars/avatar_female_m.png" failed (2: No such file or directory), client: 194.166.216.250, server: domain.com, request: "GET /threads/reizdarm.784296/styles/default/xenforo/avatars/avatar_female_m.png HTTP/1.1", host: "domain.com", referrer: "http://domain.com/threads/reizdarm.784296/"

showing clearly how browsers ignore the base tag.

My question is: What needs to be changed in XF code to accomplish that xf builds all relative URLs as absolute URLs?

Also, you may consider changing that behavior in a future version of XF once development will continue.

Thanks for hints and tips. ;)
 
Did you try the modifications I suggest on another post?
=> This should modify the Js & Css

Js modification can be done without editing a core file by simply adding a js path to config. This works perfectly.
Also some css files can be changed with our modification.

That leaves some css and all style files served with relative uri, still generating errors.

Maybe someone knows a better solution where we don't have to edit several core code parts.
However it works better than before, because the users don't have posting problems any more.
 
Are you sure the errors are coming from an actual user? Usually stuff like that is from poorly designed spiders/scripts...
 
Are you sure the errors are coming from an actual user? Usually stuff like that is from poorly designed spiders/scripts...

Good catch. ;)
But since users no longer complain about not being able to post since we changed the js path to absolute, it looks like regular users are involved also.

In addition you can find several threads about such issues here by other XenForo admins.

There is no disadvantage in using absolute or server root relative tags. And if it helps just one visitor, it's the way to go IMHO.
 
Back
Top Bottom