WP Multisite set CDN URL For Network
-
hi, this was requested nearly 3 years ago here: https://wordpress.org/support/topic/automatically-mapping-cdn-url-for-each-new-multisite-subsite/
Isn’t still no way to set global CDN url rather than each subsite, this will take ages with big sites.
-
what/how exactly do you want to map the URL ?
like
domain.com/sub1tocdn.domain.com/sub1? or something ?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/sub1but 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?
Yes structure is retained, it’s just a pure domain rewrite.
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?
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.
#!/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#http://} 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 "//$sub_path" wp --url=$site_url litespeed-option set 'cdn-mapping[url][0]' "https://cdn-1.vultrcdn.com/$sub_dir" fi doneokay , 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.comto your base domain andcdn-1.vultrcdn.comaccordingly , as well as/path/to/siteplease 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 2 years ago by
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.comto actual oneThank you so much, qtwrk.
I will be testing that and give you a shout whether it worked.
Thanks once again!
oh , forgot to mention , the PHP code needs to be placed in the
wp-config.php, next line after<?phpso it can take effect and set conf before plugins loads -
This reply was modified 2 years ago by
The topic ‘WP Multisite set CDN URL For Network’ is closed to new replies.