Host wp-content on other domain, much like a CDN

Would it be possible to host wp-content on another domain, so that all the uploads and images would go and load from there?
If so, how would I go about configuring wordpress to do this, preferably without using a third-party plugin?

Related posts

Leave a Reply

3 comments

  1. In WordPress Dashboard > Settings > Media and fill the field “Full URL path to files” with your other domain. See the screenshot below:

    Media Settings

    EDIT: I thought it would be obvious, but it isn’t. Here’s what you exactly need to do:

    1. You should map your domain to point to:

      1. public_html directory, IF it’s also your WordPress installation’s root directory.

      2. public_html/subdirectory/ directory, IF your WordPress installation is in its own subdirectory.

      3. If you have a custom path set in “Store uploads in folder”, then your domain should point to the directory ABOVE the custom uploads directory.

        For instance, lets consider this is how your settings are:

        Store uploads in this folder:media/uploads/
        (implies public_html/media/uploads/ directory — which is, as you guessed it, outside your WordPress installation directory)

        Full URL path to files:http://newdomain.com

        Then, you should make sure, http://newdomain.com points to public_html/media/uploads/ directory.

    2. Now, add the domain (or sub-domain) in the field shown in the screenshot above. Simply adding the domain, without mapping it to your WP installation, won’t do the job.

    If you don’t know how to point your domain, it’s a totally different question, and is out of the scope of WordPress.StackExchange. Google it, you should definitely get your answers. 🙂


    And as for hosting your images on a different server and different domain, you have no better choice than W3 Total Cache <– yes, a caching plugin for WordPress.

  2. My second aswer:

    to use other server it’s not easy, to use your subdomain, lets say media.domain.com it’s not hard, once i used it in my price compare site done with WP. The main sthing to speed up loadin times is to use diferent domains, and subdomains is good to, cause browsers will open new connection for them too. So use this tutorial: http://www.computingunleashed.com/host-images-in-sub-domain.html

    Server will be the same, bat browser will create new connection to load images, so loading times will be shorter (if server is not slow).

  3. Paste this to your .HTACCESS file:

    Header unset ETag
    FileETag None
    
    # BEGIN Expire headers  
    <ifModule mod_expires.c>  
        ExpiresActive On  
        ExpiresDefault "access plus 35 seconds"  
        ExpiresByType image/x-icon "access plus 2592000 seconds"  
        ExpiresByType image/jpeg "access plus 2592000 seconds"  
        ExpiresByType image/png "access plus 2592000 seconds"  
        ExpiresByType image/gif "access plus 2592000 seconds"  
        ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"  
        ExpiresByType text/css "access plus 604800 seconds"  
        ExpiresByType text/javascript "access plus 216000 seconds"  
        ExpiresByType application/javascript "access plus 216000 seconds"  
        ExpiresByType application/x-javascript "access plus 216000 seconds"  
        ExpiresByType text/html "access plus 600 seconds"  
        ExpiresByType application/xhtml+xml "access plus 600 seconds"  
    </ifModule>  
    # END Expire headers  
    
    # BEGIN Cache-Control Headers  
    <ifModule mod_headers.c>  
        <filesMatch ".(ico|jpe?g|png|gif|swf)$">  
            Header set Cache-Control "public"  
        </filesMatch>  
        <filesMatch ".(css)$">  
            Header set Cache-Control "public"  
        </filesMatch>  
        <filesMatch ".(js)$">  
            Header set Cache-Control "private"  
        </filesMatch>  
        <filesMatch ".(x?html?|php)$">  
            Header set Cache-Control "private, must-revalidate"  
        </filesMatch>  
    </ifModule>  
    # END Cache-Control Headers
    

    This will tell browser to cache all javascript, images, css to computer, so images won’t be downloaded from you until they changes.
    You can use Best browser- chrome to test it with ctrl+shift+j in timeline you can actually see how much time took to download images, the cached ones usually takes 25 ms (cause server first have to say: files is not changed so use the local copy 🙂 )