• I continued work on my website after half a year of pause. Plugin auto-updates for w3-total-cache ran ok all that time. To be sure the .htaccess is intact as well, I ran:

    $ wp w3-total-cache fix_environment apache

    Which changed 2 directives in the .htaccess file in the configuration block # BEGIN W3TC Page Cache core → <IfModule mod_rewrite.c>.

    Before fix_environment:

    RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SLASH}%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f
    RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SLASH}%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]

    After fix_environment ran:

    RewriteCond "%{DOCUMENT_ROOT}/html/apps/staging.example.com/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SLASH}%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f
    RewriteRule .* "/html/apps/staging.example.com/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SLASH}%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]
    </IfModule>

    Are you sure this went correct?

    My cache location:

    • Relative: ~/html/apps/staging.example.com/wp-content/cache/

    Old DOCUMENT_ROOT location:

    Before it was the website root, equivalent to the WordPress root (wp-config.php and .htaccess reside in that very same directory), equivalent to WordPress constant ABSPATH, equivalent to this UNIX paths:

    • Relative: ~/html/apps/staging.example.com/
    • Absolute: /data/web/shared-hosting-customer-number/html/apps/staging.example.com/

    New DOCUMENT_ROOT location

    %{DOCUMENT_ROOT} is now my user home directory, which is way above the respective domain directory, equivalent to this UNIX paths:

    • Relative: ~/
    • Absolute: /data/web/shared-hosting-customer-number/

    Are you sure this is right?

    • If that’s intentional, fine.
    • Only that as soon as some variables point higher than my domain directory root folder, I get somehow nervous… You know, cross domain access, etc… I feel better having this reported to you as a false alarm, than ignoring it.

    Your recommended “Rewrite Rules (based on active settings)”

    • shown at /wp-admin/admin.php?page=w3tc_install interestingly show the two lines in question exactly as in the old config!
    • Maybe the w3-total-cache fix_environment routine in the wp-cli plugin is outdated or otherwise erroneous?
    • This topic was modified 9 months, 1 week ago by abitofmind.
    • This topic was modified 9 months, 1 week ago by abitofmind.
    • This topic was modified 9 months, 1 week ago by abitofmind.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @abitofmind

    Thank you for reaching out and I am happy to help!

    Let me check some things about this just to make sure and I’ll get back to you once I have more details
    Thank you for your patience.

    Thread Starter abitofmind

    (@abitofmind)

    Thanks for giving a quick first response!

    Looking forward to the results of your investigation!

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @abitofmind

    Thank you for your patience

    The problem is in the DOCUMENT_ROOT variable in your environment. The webserver is not configured correctly.

    Rules are based on the DOCUMENT_ROOT environment variable coming from the server setup.
    It should point to… <something> description of docroot. It’s where the root of your web folder is on the server.

    When this variable is not set correctly, WordPress and w3tc can’t detect a path it’s running relative to a domain root and many things get broken.
    This rule is one example of it. It’s better to set it up well (contact your sys admin).
    in your case it should be set to <path before /wp-content here> /html/apps/staging.example.com

    I hope this helps!

    Thanks!

    Thread Starter abitofmind

    (@abitofmind)

    @vmarko — Thanks for looking into this!

    But I ran a whole test series again: I can tell you that DOCUMENT_ROOT is where it is supposed to be through a php test file I created, see below! And that wp w3-total-cache fix_environment apache then fixes it wrongly! But I have to tell you: I run the plugin My Private Site on this staging domain, and that possibly causes issues with routing and accessing… ?

    In the domain root folder for staging.example.com I created a new file document_root_echo.php with the contents:

    <?php echo "Document Root: " . $_SERVER['DOCUMENT_ROOT']; ?>

    It returns:

    Document Root: /data/web/customer-id/html/apps/staging.example.com

    At this time my .htaccess contains these lines (which I have manually fixed):

    RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SLASH}%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f
        RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SLASH}%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]

    I now copy .htaccess to .htaccess-BACKUP for later comparisons.

    I again run:

    wp w3-total-cache fix_environment apache
    Success: Environment adjusted.

    I inspect .htaccess and it shows despite DOCUMENT_ROOT being where it should be, w3tc nevertheless “fixes” the filepath wrongly:

    RewriteCond "%{DOCUMENT_ROOT}/html/apps/staging.example.com/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SLASH}%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f
        RewriteRule .* "/html/apps/staging.example.com/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SLASH}%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘w3-total-cache fix_environment apache sets DOCUMENT_ROOT?in htaccess correctly?’ is closed to new replies.