0

I'm attempting to use a wordpress plugin called WP Fast Cache which creates static html files from all your posts, pages and categories.

It creates the following directory structure inside wp-content:

wp_fast_cache
    example.com
        pagename
            index.html
        categoryname
            postname
                index.html

basically just a nested directory structure and a final index.html for each item.

But the htaccess edits it makes are crazy.

#start_wp_fast_cache - do not remove this comment 
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_METHOD} ^(GET)
 RewriteCond /home/user/public_html/wp-content/wp_fast_cache/%{HTTP_HOST}%{REQUEST_URI}x__query__x%{QUERY_STRING}index.html -f
 RewriteCond %{HTTP_USER_AGENT} !(iPhone|Windows\sCE|BlackBerry|NetFront|Opera\sMini|Palm\sOS|Blazer|Elaine|^WAP.*$|Plucker|AvantGo|Nokia)
 RewriteCond %{HTTP_COOKIE} !(wordpress_logged_in) [NC]
 RewriteRule ^(.*)$ /home/user/public_html/wp-content/wp_fast_cache/%{HTTP_HOST}%{REQUEST_URI}x__query__x%{QUERY_STRING}index.html [L]

 RewriteCond %{REQUEST_METHOD} ^(GET)
 RewriteCond %{QUERY_STRING} ^$
 RewriteCond /home/user/public_html/wp-content/wp_fast_cache/%{HTTP_HOST}%{REQUEST_URI}index.html -f 
 RewriteCond %{HTTP_USER_AGENT} !(iPhone|Windows\sCE|BlackBerry|NetFront|Opera\sMini|Palm\sOS|Blazer|Elaine|^WAP.*$|Plucker|AvantGo|Nokia)
 RewriteCond %{HTTP_COOKIE} !(wordpress_logged_in) [NC]
 RewriteRule ^(.*)$ /home/user/public_html/wp-content/wp_fast_cache/%{HTTP_HOST}%{REQUEST_URI}index.html [L]

</IfModule>
#end_wp_fast_cache

No matter how I try and work this out I get a 404 not found. And not the Wordpress 404, and janky apache 404.

I need to find the correct syntax to route all requests that don't exist ie: files or directories to:

wp-content/wp_fast_cache/hostname/request_uri/

So for example:

Page: example.com/about-us/ => wp-content/wp_page_cache/example.com/about-us/index.html

Post: example.com/my-category/my-awesome-post/ => wp-content/wp_fast_cache/example.com/my-category/my-awesome-post/index.html

Category: example.com/news/ => wp-content/wp_fast_cache/example.com/news/index.html

Any help is appreciated.

--EDIT--

It seems after a bunch of reading and searching that this is the Droid I'm looking for:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
    RewriteRule ^([^?]*) wp-content/wp_fast_cache/example.com/$1 [L]
</IfModule>

yet sadly ... it doesn't seem to work, what I am doing wrong?

--EDIT--

Ok, it works properly IF the cached pages are already created, but fails when trying to fetch the original pages in order to cache them.

If I have nothing in the htaccess and build all the cache pages, then add the htaccess, it will route correctly, but that won't allow me to build new pages as I add posts or pages to the blog.

Since the pages are dynamic the code I posted will try and find the pages in the cache, and since they aren't found, it creates a new cache page that is the result of the request ie: all my new pages are 404 pages :P

So I need to find a way to test for the cache page, and if not found, route to the dynamic page, then this should work perfect.

0

Looks like your first RewriteRule needs a '/' before the 'index.html'.

It would be helpful to see what the error log says - that will tell you what final URI is actually resulting in the 404, which will, in turn, probably tell you what's wrong with the rewrite rules.

Also, enabling the RewriteLog would tell us exactly what's happening, so that we're not guessing. It'll tell you what patterns were compared to what URIs, and what the result was.

  • I didn't know there was a rewrite log, thats great, where can I find/turn that on? – Vince Kronlein Nov 12 '13 at 2:30
  • Please see my updated question. – Vince Kronlein Nov 12 '13 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.