WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Supercache .htaccess problem (13 posts)

  1. wahgnube
    Member
    Posted 6 years ago #

    I am having some difficulty getting wp-super-cache to work on my journal. Briefly:

    1. Basic caching is functioning. i.e., I see the message
    <!-- Cached page served by WP-Cache -->
    on subsequent reloads of pages.

    2. Super-cache pages are being generated. i.e., The folder /wp-content/cache/supercache exists, and the static HTML files corresponding to pages requested previously are being generated. Here is an example, which contains the comment
    <!-- super cache -->
    at the end of the file.

    3. However, my .htaccess file, which contains the line
    RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]
    fails to redirect browsers to these Super-cached files. Therefore, all I see when I load pages is the comment generated by basic wp-cache.

    How do I debug .htaccess redirects? Has anyone else experienced this problem and solved it?

    I am trying this as an arbitrary user (not logged in, no comments, browser cache/cookies cleared).

  2. Donncha O Caoimh
    Member
    Posted 6 years ago #

    I tried your example link and got a warning about snooping around. Does the problem resolve itself if you remove that rewrite rule? I presume there's a .htaccess in wp-content/ ? Remove that and it might work ok.

  3. wahgnube
    Member
    Posted 6 years ago #

    Thank you for your help.

    No, I'm afraid you received the warning because index.html from that folder had been cleared (I suppose since that page hadn't been accessed for some time). I have accessed the page once more (regenerating the cached file), and the link works once more.

    I don't have a .htacess in wp-content. The rule that took you took you to the warning exists in / . This rewrite rule that points the browser to the snooping warning only kicks in when there isn't a index document in a directory. And it did because the cache had been cleared (because of the appropriate time outs, I suppose).

  4. wahgnube
    Member
    Posted 6 years ago #

    I believe the problem is that the the following rewrite condition
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
    is not engaging, even though the cached file exists.

  5. wahgnube
    Member
    Posted 6 years ago #

    The problem seems to have resolved itself when I replaced the variables DOCUMENT_ROOT and HTTP_HOST by their actual values!

  6. ChrisSamuel
    Member
    Posted 6 years ago #

    OK, because I'm using vhosts in my Apache 2.2 config I found that %{DOCUMENT_ROOT} was being set to just /htdocs. So to fix it
    I just needed to prefix it with /var/www/%{HTTP_HOST}. You can verify whether or not this is happening for you too by looking at the output of the phpinfo() "Server variables" section.

    My patch was:

    --- .htaccess.hmm       2008-04-06 18:58:17.000000000 +1000
    +++ .htaccess   2008-04-06 20:06:50.000000000 +1000
    @@ -5,12 +5,12 @@
     RewriteCond %{QUERY_STRING} !.*s=.*
     RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$
     RewriteCond %{HTTP:Accept-Encoding} gzip
    -RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
    +RewriteCond /var/www/%{HTTP_HOST}/%{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
     RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]
    
     RewriteCond %{QUERY_STRING} !.*s=.*
     RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$
    -RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
    +RewriteCond /var/www/%{HTTP_HOST}/%{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
     RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]
     </IfModule>

    Hope that helps!
    Chris

  7. wahgnube
    Member
    Posted 6 years ago #

    Thanks for the tip, Chris. I was looking for a way to see the values of HTTP_HOST AND DOCUMENT_ROOT.

    Now here's the interesting (confusing) thing.

    According to the output of phpinfo(), both these environment variables appear to be set correctly. However (and I just tried this again), replacing the actual path by %{DOCUMENT_ROOT} causes the condition to fail.

  8. ear1grey
    Member
    Posted 6 years ago #

    I just solved a problem with identical symptoms. The problem appeared to be fed by these factors:

    • I have a permalink structure of /%postname%/
    • I have wordpress in a different folder

    The key lines of my rewrites are included below. I have:

    1. added /wp to the start of the path manually
    2. changed the regex replace from $1 to $0
    3. removed from after $0

    RewriteCond %{DOCUMENT_ROOT}/wp/wp-content/cache/supercache/%{HTTP_HOST}/$0index.html.gz -f
    RewriteRule ^(.*) /wp/wp-content/cache/supercache/%{HTTP_HOST}/$0index.html.gz [L]

    RewriteCond %{DOCUMENT_ROOT}/wp/wp-content/cache/supercache/%{HTTP_HOST}/$0index.html -f
    RewriteRule ^(.*) /wp/wp-content/cache/supercache/%{HTTP_HOST}/$0index.html [L]

  9. wahgnube
    Member
    Posted 6 years ago #

    I see.

    I assumed $1 held the match within the first parenthesis in the RewriteRule regexp. What does $0 hold?

  10. Lenary
    Member
    Posted 6 years ago #

    yeah, i'm having problems too - using wordpress-mu
    the wordpress is in var/www/blogs because we only serve one domain from the server. below is the code in the .htaccess

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /blogs/
    RewriteCond %{QUERY_STRING} !.*s=.*
    RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
    RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
    RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteCond %{DOCUMENT_ROOT}/blogs/wp-content/cache/supercache/%{HTTP_HOST}/blogs/$1index.html.gz -f
    RewriteRule ^(.*) /blogs/wp-content/cache/supercache/%{HTTP_HOST}/blogs/$1index.html.gz [L]

    RewriteCond %{QUERY_STRING} !.*s=.*
    RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
    RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
    RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
    RewriteCond %{DOCUMENT_ROOT}/blogs/wp-content/cache/supercache/%{HTTP_HOST}/blogs/$1index.html -f
    RewriteRule ^(.*) /blogs/wp-content/cache/supercache/%{HTTP_HOST}/blogs/$1index.html [L]

    # END WordPress

    i can only see the front page. no more
    i tried to put /var/www/blogs instead of /var/www/%{HTTP_HOST} but that didn't help. what should i do?

  11. Lenary
    Member
    Posted 6 years ago #

    ok, properly installed it using above method, but it still doesn't work
    mod mimes enabled, mod rewrite enabled, and fancy permalinks already used
    put the folder in wp-content/mu-plugins as opposed to wp-content/plugins
    i now have no clue what is going wrong, but i do know that it isnt working, and that it's not telling me why
    should i have put it in both directories?

  12. beernews
    Member
    Posted 5 years ago #

    I tried your example link and got a warning about snooping around. Does the problem resolve itself if you remove that rewrite rule? I presume there's a .htaccess in wp-content/ ? Remove that and it might work ok.

    Is there a way to block parent directory access for images, etc. and still have supercache work successfully? I created an .htaccess file in wp-content with this code from blogsecurity which, of course, made supercache stop working:

    Order Allow,Deny
    Deny from all
    <Files ~ ".(css|jpe?g|png|gif|js)$">
    Allow from all
    </Files>
  13. beernews
    Member
    Posted 5 years ago #

    Saw that something like this would work...

    <Files "wp-cache-phase2.php"
    Allow from all
    </Files>

    If I want to allow multiple files, would this be correct syntax?

    <Files "wp-cache-phase2.php,wp-cache-phase1.php,wp-cache-config-sample.php,wp-cache-base.php,searchengine.php,wp-cache-config.php,advanced-cache.php">
    Allow from all
    </Files>

    Not sure if I would need to include directories as well but I imagine so.

Topic Closed

This topic has been closed to new replies.

About this Topic