Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support qtwrk

    (@qtwrk)

    what/how exactly do you want to map the URL ?

    like domain.com/sub1 to cdn.domain.com/sub1 ? or something ?

    Thread Starter Omar Khalil

    (@donmccoy)

    Hi, it’s the Vultr new CDN. it’s completely different domain no CNAME. so it would be:
    domain1.com/sub1 to cdn-1.vultrcdn.com/sub1

    Plugin Support qtwrk

    (@qtwrk)

    but do they retain same structure ? like

    domain1.com/sub1 to cdn-1.vultrcdn.com/sub1
    
    domain1.com/sub2 to cdn-1.vultrcdn.com/sub2
    
    domain1.com/sub3 to cdn-1.vultrcdn.com/sub3
    
    domain1.com/sub4 to cdn-1.vultrcdn.com/sub4

    ?

    Thread Starter Omar Khalil

    (@donmccoy)

    Yes structure is retained, it’s just a pure domain rewrite.

    Plugin Support qtwrk

    (@qtwrk)

    hm ? I think I might be able to work out some code snippet for you

    but I assume it’s unrealistic to actually have sub site named as sub1 , sub2, sub3, …etc ?

    I assume it could be like

    domain1.com/aaa to cdn-1.vultrcdn.com/aaa
    
    domain1.com/bbb to cdn-1.vultrcdn.com/bbb
    
    domain1.com/ccc to cdn-1.vultrcdn.com/ccc
    
    domain1.com/ddd to cdn-1.vultrcdn.com/ddd

    ?

    Thread Starter Omar Khalil

    (@donmccoy)

    That would be awesome thank you!
    sub1 and sub2 just for the sake of the example you made.

    After the / it could be anything according to the website needs, for our website it’s region code for multilingual so /en, /fr etc.

    So yes your assumption is still standing correct for Vultr CDN.

    Plugin Support qtwrk

    (@qtwrk)

    #!/bin/bash
    
    site_url_list=$(wp site list --field=url --path=/path/to/site)
    
    for site_url in $site_url_list; do
        if [ "$site_url" != "https://base_domain.com/" ]; then
            sub_path=${site_url#https://}
            sub_path=${sub_path#https://}
            sub_dir=$(echo $site_url | sed 's|https://base_domain.com/||' | sed 's|/$||')
            wp --url=$site_url litespeed-option set cdn true
            wp --url=$site_url litespeed-option set cdn-ori "https://$sub_path"
            wp --url=$site_url litespeed-option set 'cdn-mapping[url][0]' "https://cdn-1.vultrcdn.com/$sub_dir"
        fi
    done

    okay , I spent a lot of time try to get a PHP way by conf constant define , but seems failed , however I come up an alternative with WP CLI command to set options

    replace base_domain.com to your base domain and cdn-1.vultrcdn.com accordingly , as well as /path/to/site

    please do make a backup of database beforehand , just in case it didn’t work out , you can revert it instead of manually go through all sites

    • This reply was modified 9 months, 1 week ago by qtwrk.
    Plugin Support qtwrk

    (@qtwrk)

    okay , after bugged our dev to death , I finally got this

    if (isset($_SERVER['REQUEST_URI']) && preg_match('#^/([^/]+)#', $_SERVER['REQUEST_URI'], $matches)) {
    define( 'LITESPEED_CONF', true );
    define( 'LITESPEED_CONF__CDN', true );
    $cdn_url_path = explode('/', trim($_SERVER['REQUEST_URI'], '/'));
    $cdn_origin_url = '//' . $_SERVER['SERVER_NAME'] . '/' . $cdn_url_path[0] . '/';
    define( 'LITESPEED_CONF__CDN__ORI',[ $cdn_origin_url ] );
    define('LITESPEED_CONF__CDN__MAPPING', [
        [ 'url'=> 'https://cdn.domain.com/' . $cdn_url_path[0] . '/' , 'inc_img'=>true, 'inc_css'=>true, 'inc_js'=>true, 'filetype' => ['.aac', '.css', '.eot', '.gif', '.jpeg', '.jpg', '.js', 
        '.less', '.mp3', '.mp4', '.ogg', '.otf', '.pdf', '.png', '.svg', '.ttf', '.webp', '.woff', '.woff2'] ]
    ]);
    }

    please give it a try , replace cdn.domain.com to actual one

    Thread Starter Omar Khalil

    (@donmccoy)

    Thank you so much, qtwrk.

    I will be testing that and give you a shout whether it worked.

    Thanks once again!

    Plugin Support qtwrk

    (@qtwrk)

    oh , forgot to mention , the PHP code needs to be placed in the wp-config.php , next line after <?php so it can take effect and set conf before plugins loads

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘WP Multisite set CDN URL For Network’ is closed to new replies.