wp-media / wp-rocket

Performance optimization plugin for WordPress
https://wp-rocket.me
GNU General Public License v2.0
680 stars 211 forks source link

Wrong CSS/JS link in subdomain #6738

Open bugrevealingbme opened 1 week ago

bugrevealingbme commented 1 week ago

I set up a subdomain with Polylang. The CSS and JS on the pages should come from the main domain, but it adds the subdomain link to them and the page breaks. I tried excluding subdomains from the cache, but this does not work.

Also i tried this function:

function replace_subdomains_with_main_domain($url) {
    global $subdomains, $main_domain;
    foreach ($subdomains as $subdomain) {
        if (strpos($url, $subdomain) !== false) {
            return str_replace($subdomain, $main_domain, $url);
        }
    }
    return $url;
}

// CSS, JS ve ekli medya URL'leri için filtreler
add_filter('stylesheet_uri', 'replace_subdomains_with_main_domain');
add_filter('script_loader_src', 'replace_subdomains_with_main_domain');
add_filter('style_loader_src', 'replace_subdomains_with_main_domain');
add_filter('wp_get_attachment_url', 'replace_subdomains_with_main_domain');
add_filter('wp_get_attachment_image_srcset', 'replace_subdomains_with_main_domain');
add_filter('the_content', 'replace_subdomains_with_main_domain');

add_filter('rocket_buffer', 'replace_subdomains_with_main_domain', 999999); 
add_filter('rocket_cache_reject_cookies', 'replace_subdomains_with_main_domain');
bugrevealingbme commented 1 week ago

i fixed with: RewriteCond %{REQUEST_URI} \/$