Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Static Publisher - .htaccess - not accessing the .html files

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

Page: 1
Go to End
Author Topic: 2720 Views
  • Gutur
    Avatar
    Community Member
    17 Posts

    Static Publisher - .htaccess - not accessing the .html files Link to this post

    Hi everyone, I fiddled with this for a few hours now and I can't get it to work.
    I followed the instructions and also read this post.
    I'm testing this on a silverstripe in a subdirectory (/mydir/) of my server and the CMS per se works perfect.
    So, on http://www.mysite.com/mydir/dev/buildcache?flush=1 it also builds the cache pages just fine, but I can't get the .htaccess right...

    This is what resides in /mydir/.htaccess:

    ### SILVERSTRIPE START ###
    <Files *.ss>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
    </Files>

    <IfModule mod_rewrite.c>
    RewriteEngine On
    #RewriteBase /mydir

    ## CONFIG FOR DEV ENVIRONMENTS

    # Cached content - mydir subdirectory
    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{REQUEST_URI} ^/mydir/(.*)$
    RewriteCond %{REQUEST_URI} /mydir/(.*[^/])/?$
    RewriteCond %{DOCUMENT_ROOT}/mydir/cache/%1.html -f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /mydir/cache/%1.html [L]

    # Cached content - homepage
    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{REQUEST_URI} ^/mydir/?$
    RewriteCond /mydir/cache/index.html -f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /mydir/cache/index.html [L]

    ## CONFIG FOR TEST/LIVE ENVIRONMENTS

    # Cached content - live webserver
    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{REQUEST_URI} /(.*[^/])/?$
    RewriteCond %{DOCUMENT_ROOT}/cache/%1.html -f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /cache/%1.html [L]

    # Cached content - homepage
    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{REQUEST_URI} ^/?$
    RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /cache/index.html [L]

    ## DYNAMIC CONFIG
    # Dynamic content
    RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
    RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
    </IfModule>
    ### SILVERSTRIPE END ###

    But somehow the rewriterules never kick in. It always gives back the data from the CMS.
    I know a bit about apache rewriterules and tried out a lot, patched here and there to find what's keeping it from kicking in and so on. But now i think I can't look straight at it anymore and have to ask for help

    Does anybody find the general error in this .htaccess?

  • Gutur
    Avatar
    Community Member
    17 Posts

    Re: Static Publisher - .htaccess - not accessing the .html files Link to this post

    Ok, found out some more. With this it works, partially:

    RewriteEngine On
    #RewriteBase /mydir

    ## CONFIG FOR DEV ENVIRONMENTS

    # Cached content - mydir subdirectory
    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{REQUEST_URI} ^/mydir/(.*)$
    RewriteCond %{REQUEST_URI} /mydir/(.*[^/])/?$
    #RewriteCond %{DOCUMENT_ROOT}/mydir/cache/%1.html -f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /mydir/cache/%1.html [L]

    # Cached content - homepage
    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{REQUEST_URI} ^/mydir/?$
    #RewriteCond %{DOCUMENT_ROOT}/mydir/cache/index.html -f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /mydir/cache/index.html [L]

    It now hits for all pages that have a corresponding "name.html" in the cache directory but since two lines are commented out it never falls back if there isn't one.
    Seems that the check "-f (is regular file)" always returns False... at least on my host.
    Or does anyone find an error in those two lines and me is just too stoopied?
    ..brain... hurts ... must ... look at ... something ... different ....

  • Gutur
    Avatar
    Community Member
    17 Posts

    Re: Static Publisher - .htaccess - not accessing the .html files Link to this post

    WEEEELLLLLLLL with my ISP "%{DOCUMENT_ROOT}" isn't giving back the document root, no way, Sir!
    Figured it out via phpinfo(), hardhacked it into the .htaccess and voila, works like a charm.
    Man, is that ISP crap, going to change tomorrow Now for some Episodes of Spongebob to wipe my brain clear...

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: Static Publisher - .htaccess - not accessing the .html files Link to this post

    Hi,

    When you run your site from cache-- do all the links show up with "/index.php/" in front of them?? This is really killing me. The base href is appending this for some weird reason:

    <base href="http://www.mysite.com/index.php/" />

    Have you see this?

    Thanks,
    Garrett

  • TF-35Lightning
    Avatar
    Community Member
    137 Posts

    Re: Static Publisher - .htaccess - not accessing the .html files Link to this post

    Gutur I am having some similar trouble getting the static publisher to function, is there any chance you could please post up your .htaccess file so I can take a look.

    My thread related to getting this working is at.

    http://www.silverstripe.org/customising-the-cms/show/284249?showPost=284457

    I'm on 2.4, but if your still on 2.3 it might still help.

    Any help would be great

  • TF-35Lightning
    Avatar
    Community Member
    137 Posts

    Re: Static Publisher - .htaccess - not accessing the .html files Link to this post

    -

    2720 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.