Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » lots of 404 errors with relative pathing with the blog widget

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 838 Views
  • iandouglas736
    Avatar
    Community Member
    8 Posts

    lots of 404 errors with relative pathing with the blog widget Link to this post

    Hey all.

    I've noticed over the past month using SilverStripe that my error_log is filling up with 404 errors, mostly associated with things like this:

    http://mydomain.com/my-blog-article/jsparty/something/whatever.js
    or
    http://mydomain.com/my-blog-article/themes/paddygreen/css/typography.css

    (I should mention that SilverStripe is installed at the root level of my web site, ie: right in public_html, not a subfolder like /cms/)

    So I added the following rules to my .htaccess, and the errors went away:

    RewriteRule (.*)/jsparty/(.*) http://mydomain.com/jsparty/$2 [L]
    RewriteRule (.*)/blog/(.*) http://mydomain.com/blog/$2 [L]
    RewriteRule (.*)/themes/(.*) http://mydomain.com/themes/$2 [L]

    Obviously, if you installed SilverStripe under a root folder like /cms/ you'd change the rules to be something more like:

    RewriteRule cms/(.*)/jsparty/(.*) http://mydomain.com/cms/jsparty/$2 [L]
    RewriteRule cms/(.*)/blog/(.*) http://mydomain.com/cms/blog/$2 [L]
    RewriteRule cms/(.*)/themes/(.*) http://mydomain.com/cms/themes/$2 [L]

    After tracing through much of the code, I see where a few calls to the Requirements class are using a variable like this:

    Requirements::css($_CSS_MANIFEST[$name]['unthemed'], $media);
    but most times not:
    Requirements::javascript('jsparty/scriptaculous/effects.js');

    It seems the code that inserts the filename into the output HTML does a check if the file exists, likely using file_exists(), since prepending a '/' on these calls caused huge issues (file_exists() uses relative pathing, so prepending a '/' would start looking at the root level of your filesystem, not from a web-relative path). I know this because prepending a '/' made those javascript/css elements disappear completely from the output HTML, telling me that if the file_exists() call failed that the css/javascript wasn't injected into the output HTML.

    So it seemed the only way to correct this behavior was via .htaccess, and my fix as mentioned above seems to be working quite well.

    Still, it raises the issue of why the blog widget doesn't account for the article name when looking for the /jsparty/ or /blog/ paths for other elements.

    Can anyone think of a non-htaccess way to solve this in the code?

    838 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.