botty
Forum Replies Created
-
Forum: Plugins
In reply to: [W3 Total Cache] Auto Minify using wrong pathsI FOUND A FIX!!!
The problem, as @levymetal said, is in the $_SERVER[‘SCRIPT_FILENAME’] in w3_get_document_root() inside /inc/define.php
I still don’t know why it takes the wrong file name, but I think it’s an error, or a different way, in which the LiteSpeed server compared to Apache server is configured, because my hoster switched from Apache to LiteSpeed overnight (without me knowing) and before this change it was working perfectly.
In my case (sometimes, not always) it returned: “/home/xxxxx/public_html/wp-content/plugins/w3-total-cache/pub/minify.php/0nify.php/0inify.php”
instead of “/home/xxxxxx/public_html/wp-content/plugins/w3-total-cache/pub/minify.php”To fix it, I changed this line (760) in the file /inc/define.php of the plugin
$document_root = substr(w3_path($_SERVER['SCRIPT_FILENAME']), 0, -strlen(w3_path($_SERVER['PHP_SELF'])));with this:
$filename = strtolower(w3_path($_SERVER['SCRIPT_FILENAME'])); if (substr_count($filename, ".php") > 1) { $pos = strpos($filename, ".php"); $filename = substr($filename, 0, $pos+4); } $document_root = substr($filename, 0, -strlen(w3_path($_SERVER['PHP_SELF'])));Essentially it checks if there is more than one “.php” in the file name (which, theoretically, it shouldn’t be the case) then deletes all the character after the first “.php” and goes on normally.
BEWARE:
On my site this workaround works perfectly, but you should implement it at your own risk, because you could have a configuration different from mine.
I have a pretty standard configuration (shared hosting, WP installed in root, not in sub-folder, no multisite network) and the minify function doesn’t parse any file with parameters (file.ext?par=value) so I know for sure that if there is more than one “.php” is an error (if you use parameters, it may be possible that the presence of more than one “.php” is correct and intentional, so check carefully all the file)IMPORTANT!!!
The function w3_get_document_root() that I modified is used generally by W3 Total Cache and not only by the minify function. So please be aware of the change you are making!!!I hope that this could be useful to other people too.