Multisite – Serve static content from a cookieless domain

I would like to “Serve static content from a cookieless domain” on my multisite at ChristianGays.com. I need help setting it up. I have found a lot of information on the internet so am more than a little confused. At this point I have created a new sub-domain called static.christiangays.com. I have configured A record.

My wp-config.php file already has

define( ‘WP_CONTENT_URL’, ‘https://christiangays.com/mary-content’ );

define( ‘WP_CONTENT_DIR’, ‘/home/mary/public_html/mary-content’ );

Instructions are to add

define(“WP_CONTENT_URL”, “http://static.domain.com&#8221:wink:;

define(“COOKIE_DOMAIN”, “domain.com”:wink:;

but I can tell by looking at it that that won’t work.

I have also seen additions to make to .htaccess file but again, I don’t think they will work.

Can you tell me how to proceed please. I need to know

1. what do I put in wp-config.php

2. what do I put in .htaccess

3. what do I do next? i.e. can I use wp-rocket, or do I need to load all CSS files for all sites in the static sub-domain?

Support Access is granted.

  • Sohag Ronjon Dey
    • QA

    Hi Mary,

    Thanks for contacting and I hope that you are having a beautiful day. :slight_smile:

    Please check the following url

    https://scottdeluzio.com/serve-images-from-sub-domain-in-wordpress/

    I have configured my uploads directory according to this article. This works for the images and after that I have also created a subdomain for content folder and I pointed the domain to my wp-content folder. And configured the WP_CONTENT_URL and WP_PLUGIN_URL in my wp-config file. And also added code to .htaccess file to redirect to my static domain. All works for my site. Here are the codes I added.

    I have added this to my wp-config.php

    define('WP_CONTENT_URL', 'http://static.mysite.com');
    define('COOKIE_DOMAIN', '');
    define('WP_PLUGIN_URL', 'http://static.mysite.com/plugins');

    to .htaccess

    RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://img.mysite.com/$1
    RedirectMatch 301 ^/wp-content/(.*)$ http://static.mysite.com/$1

    Please replace the domains and subdomains according to your ones.

    Hope this will help.

    Please let us know if you need any further help.

    Cheers,

    Sohag

  • Mary
    • Wisp of the WP Loop

    Thank you for your help Sohag. This link is the best one I’ve read so far, but I don’t think you get it. For starters, if I add

    define(‘WP_CONTENT_URL’, ‘http://static.mysite.com&#8217:wink:;

    define(‘COOKIE_DOMAIN’, ”:wink:;

    define(‘WP_PLUGIN_URL’, ‘http://static.mysite.com/plugins&#8217:wink:;

    then I will have 2 define(‘WP_CONTENT_URL’:wink:s and that can’t possibly work.

    And can you please explain why I would add

    define(‘WP_PLUGIN_URL’, ‘http://static.mysite.com/plugins&#8217:wink:;

    That is not mentioned in the link you sent.

    I’d like to resolve these issues before I try to proceed. I was really hoping for more detailed information specific to my website like Adam and James Morris and Nithin and some of the others give.

  • Sohag Ronjon Dey
    • QA

    Hi Mary,

    Thanks for the quick reply.

    And also sorry if I made any confusion. Actually I have tested the instructions provided on the reference url and also the code on my site that I provided above and that works. However I have also checked the code by removing the

    define('COOKIE_DOMAIN', '');
    define('WP_PLUGIN_URL', 'http://static.mysite.com/plugins');

    This also works. The WP_PLUGIN_URL and WP_CONTENT_URL are two different constants. One is the content url and one is the plugin url. I have added those for making sure if the plugin url is not missed for any of the plugins. However it works both with these codes and without these codes.

    For your site please create a subdomain named like static.christiangays.com (you can use other name in place of static) and point this domain to home/mary/public_html/mary-content

    add only the following to wp-config.php

    define('WP_CONTENT_URL', 'https://static.christiangays.com');

    Please make sure you add this code before

    /* That's all, stop editing! Happy blogging. */

    And also add the following to .htaccess

    RedirectMatch 301 ^/mary-content/(.*)$ https://static.christiangays.com/$1

    Please make sure if static.christiangays.com is with https or http and use accordingly in the code above.

    And for uploads you can follow the instructions provided on the url

    https://scottdeluzio.com/serve-images-from-sub-domain-in-wordpress/

    Again I am really very sorry if I missed anything and made any confusion. If you need any further help just let me know. I will try my best to help.

    Please let me know.

    Best regards,

    Sohag.

  • Mary
    • Wisp of the WP Loop

    I have already created static.christiangays.com, but I have configured the A record to be directed to the IP of the site. See screenshot:

    [attachments are only viewable by logged-in members]

    I don't know how to direct it to home/mary/public_html/mary-content

  • Sohag Ronjon Dey
    • QA

    Hi Mary,

    Thanks for the quick reply.

    If you are creating a subdomain from cpanel there may be an option to enter document root. Please enter the path home/mary/public_html/mary-content in the document root. If this does not work then enter public_html/mary-content instead in the document root. Please check the screenshot.

    [attachments are only viewable by logged-in members]

    If this does not match your cpanel subdomain setup then could you please send us your details through our contact form so I can try to investigate this further on your side,

    https://wpmudev.com/contact/#i-have-a-different-question using this template:

    Subject: "Attn: Sohag"

    -WordPress admin username

    -WordPress admin password

    -login url

    -ftp and cpanel credentials (host/username/password)

    -link back to this thread for reference

    -any other relevant urls

    Select "I have a different question" for your topic – this and the subject line ensure that it gets assigned to me

    Please DO NOT post the credentials here as this is a public forum, also would you mind me doing some basic troubleshooting such as temporary deactivating all plugins?

    Please let me know when you do so.

    Cheers,

    Sohag

  • Mary
    • Wisp of the WP Loop

    Thank you Sohag. I know how to set up sub-domains in cPanel but my Systems Admin doesn’t want me to do it that way. He wants me to do it via GoDaddy, who has my domain name registrations.

    I have sent you credentials for logging into my site, SFTP, cPanel and GoDaddy.

  • Adam
    • Support Gorilla

    Hi epsilon

    I’m happy that these posts are useful for you!

    I’ve edited your post and removed the link from it. Please, do not use the forum to try to get links to your site as this doesn’t add anything to the discussion. Also, the links from here are “non follow” links so they don’t add any “SEO juice”.

    You’re however more than welcome to showcase your site to WPMU DEV Members and/or ask for their feedback/opinions/advice on the Members only forum here: https://wpmudev.com/forums/forum/showcase

    I hope that makes sense :slight_smile: Thank you for being the part of our community!

    Best regards,

    Adam

  • Adam
    • Support Gorilla

    Hi Mary!

    my Systems Admin doesn’t want me to do it that way.

    Is there any particular reason for this? Setting up a subdomain in cPanel is a fairly standard procedure and doesn’t bring any complications to the setup. In this case the important part is to point the “root folder” (a.k.a “document root”:wink: of the sub-domain to the specific folder of your WordPress install and that cannot be done using DNS solely – which would be the case if you could only use GoDaddy’s domain registration/management panel.

    Best regards,

    Adam

  • Mary
    • Wisp of the WP Loop

    Thank you Adam. I don’t know why he wants to do it that way. I did add the site as a sub-domain using cPanel, but it isn’t working so I think I’m going to have to wait until my Systems Admin is available and get him to look after it. I will close the ticket since it just seems beyond my capabilities.

    Thanks everyone for all the help.