Powered Cache relies on the file-optimizer.php file, found in the plugin’s ‘includes’ directory, for optimizing CSS and JS files. Modifying the file optimizer offers several benefits:

  • Enhances CDN Compatibility: Some CDN services may bypass requests when they detect a “.php” in the resource URL. Rewriting the file optimizer resolves this issue.
  • Addresses WAF Rules: If you have set up Web Application Firewall (WAF) rules that prevent file-optimizer.php from executing, using a rewrite can circumvent this limitation.
  • Improved Resource Naming: Utilizing rewrite rules allows for more intuitive and organized naming of related resources.

Example URL Without rewrite:

https://example.com/wp-content/plugins/powered-cache/includes/file-optimizer.php??/wp-includes/css/dashicons.css,/wp-includes/css/admin-bar.css?m=1677524837&minify=1

Example URL With rewrite:

https://example.com/_static/??/wp-includes/css/dashicons.css,/wp-includes/css/admin-bar.css?m=1677524837&minify=1

If your server is compatible with .htaccess and you’ve enabled automatic .htaccess configuration, simply activating this feature is all you need to do. However, if you’d rather handle rewrite rules manually, you can apply the following code snippets:

Apache/LiteSpeed:

<IfModule mod_rewrite.c>
  # Enable rewrite engine
  RewriteEngine On
  # Redirect all requests starting with /_static/
  RewriteRule ^_static/.* wp-content/plugins/powered-cache/includes/file-optimizer.php [L]
</IfModule>

Nginx:

location /_static/ {
        fastcgi_pass unix:/var/run/fastcgi.sock;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/wp-content/plugins/powered-cache/includes/file-optimizer.php;
}

If you are using runcloud for server management, then add this as a custom nginx rule with choosing “location.main-before” for the location

location /_static/ {
        fastcgi_pass unix:/var/run/{APP_NAME}.sock;
        include /etc/nginx-rc/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME  $document_root/wp-content/plugins/powered-cache/includes/file-optimizer.php;
}