Title: How make WP multisite create sites in https
Last modified: August 31, 2016

---

# How make WP multisite create sites in https

 *  [webtechIMT](https://wordpress.org/support/users/webtechimt/)
 * (@webtechimt)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/)
 * Hi,
 * My WP multisite is all in https (fton and backoffice). But when a user create
   a site, the site has the site_url and home values in wp_options with http:// (
   it should be [https://](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/?output_format=md)).
 * The result is : media are added with http:// and don’t display (the browser don’t
   display http in a https page.
 * How solve this ?
 * Thanks.
    Oli

Viewing 13 replies - 1 through 13 (of 13 total)

 *  Moderator [Bet Hannon](https://wordpress.org/support/users/bethannon1/)
 * (@bethannon1)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934103)
 * Are you running subdomain or subdirectory multisite?
 * What type of SSL did you set up on this network? Single site or wildcard subdomains?
 * Have you made any edits to your .htaccess for implementing the SSL, and if so
   what are they?
 * If you go into Network Admin–Sites–edit a subsite, on the Settings tab, are the
   Siteurl and Home set to HTTPS? And if not, does making them so change your issue?
 *  Thread Starter [webtechIMT](https://wordpress.org/support/users/webtechimt/)
 * (@webtechimt)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934121)
 * I’m running subdomain multisite with a wildcard cartificate.
 * For the http server configuration, I redirect all http traffic to https (301 
   redirection).
 * When a new site is created, if I go into Network Admin–Sites–edit a subsite, 
   on the Settings tab, the Siteurl and Home aren’t set to HTTPS but in HTTP. I 
   have to do it manually, and it works, but, of course, I want that it’ll be done
   automatically.
 *  [ncsumarit](https://wordpress.org/support/users/ncsumarit/)
 * (@ncsumarit)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934212)
 * What webtechIMT said. Having the same problem here. Our multisite environment
   is using a wildcard SSL for subdomains. New sites are being generated with http
   and even though our network forces https, files and images on the site are still
   being served over http unless we go in and update each new site as its created(
   and since we get 5-10 a week we’d really not edit these manually).
 * Would love a config option for MU. Prefer not to use the Force https plugin.
 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [10 years, 3 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934213)
 * I had the same problem and the way I’ve done it in the past is inelegant but 
   it worked for me. All of the sites in my network are HTTPS based (it’s not a 
   large installation). So I made a list of all of my URLs and used wp-cli to search
   and replace all instances of that URL with the HTTPS version.
 * My site root was `example.com` and I had the following sites defined.
 *     ```
       http://example.com
       http://site1.example.com
       http://site2.example.com
       http://site3.example.com
       http://domainmapped.com
       ```
   
 * I installed wp-cli on my server and ran these commands.
 * [http://wp-cli.org/](http://wp-cli.org/)
 *     ```
       wp db export ~/example.com-site.sql
       wp search-replace --network --dry-run http://example.com https://example.com
       ```
   
 * See the `--network --dry-run` part? The `--network` was get all tables in the
   site and the `--dry-run` was to just produce a report without changing actually
   anything. That was to validate that my command was good.
 * Once I was satisfied I ran the same command without `--dry-run`
 *     ```
       wp search-replace --network http://example.com https://example.com
       ```
   
 * I repeated that process (less the `db export`) for all the URLs on my list. I
   checked and my URLs and media were now all HTTPS based and have been since.
 * If something went horrifically wrong (and it did, I fat fingered the URL) then
   I just restored the DB SQL backup I made before I tried to make changes.
 *     ```
       wp db import ~/example.com-site.sql
       ```
   
 * You can use other search and replace methods but I really like wp-cli.
 *  Moderator [Bet Hannon](https://wordpress.org/support/users/bethannon1/)
 * (@bethannon1)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934214)
 * Jan, would this search & replace also work if I just exported the db, opened 
   the .sql file as a text file and replaced all “http:” with “https:”, then import
   that new file into a new db, then switch the db creds in wp-config.php to the
   new db? (I was going to overwrite the orig db, but this would make it really 
   easy to switch right back if it doesn’t work.)
 * And more importantly, will this make it so that all NEW subsites created are 
   https — which was webtechIMT’s question in the first place? 🙂
 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [10 years, 3 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934215)
 * I think editing the ASCII SQL file won’t cover everything. It might but when 
   I did that before I noticed somethings missing. It left off the serialized data
   I think.
 * > And more importantly, will this make it so that all NEW subsites created are
   > https — which was webtechIMT’s question in the first place? 🙂
 * _*Adds new site to network*_
 * Now THAT’S annoying. The new site was `http://`. There’s got to be a way to hook
   that…
 * [https://developer.wordpress.org/reference/hooks/pre_add_site_option_option-3/](https://developer.wordpress.org/reference/hooks/pre_add_site_option_option-3/)
 * I will play around. If the URL can be fixed when or just before the site is added
   to the network then this might be fixable via an mu-plugin.
 *  Moderator [Bet Hannon](https://wordpress.org/support/users/bethannon1/)
 * (@bethannon1)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934216)
 * Can everyone verify for me that they have https set for siteurl & home in main
   site settings and are still getting new http subsites? That’s my understanding
   of the original post above. I’m doing a little more checking, and more knowledgeable
   minds seem to think having those settings in the main site should carry over 
   to subsites.
 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [10 years, 3 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934217)
 * > Can everyone verify for me that they have https set for siteurl & home in main
   > site settings and are still getting new http subsites
 * Verified. 😉
 * My URLs are all HTTPS based including the SiteURL and WordPress address for the
   main site.
 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [10 years, 3 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934218)
 * It is doable with a plugin but I am pretty sure that WordPress should pick up
   the scheme correctly. I’m not sure why it didn’t.
 * Try this plugin by copying the file into the `mu-plugins` directory.
 *     ```
       /*
       Plugin Name: Make new sites in the network with https URLs
       Description: Force new sites in a multisite network to use HTTPS as the scheme.
       Plugin Author: Jan Dembowski
       */
   
       add_action( 'wpmu_new_blog', 'mh_new_site_http', 10, 6 );
   
       function mh_new_site_http( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
   
               switch_to_blog( $blog_id );
   
               $mh_old_home_url = trailingslashit( esc_url( get_option( 'home' ) ) );
               $mh_old_site_url = trailingslashit( esc_url( get_option( 'siteurl' ) ) );
   
               $mh_new_home_url = preg_replace( '/^http:/' , 'https:' , $mh_old_home_url );
               $mh_new_site_url = preg_replace( '/^http:/' , 'https:' , $mh_old_site_url );
   
               update_option( 'home', $mh_new_home_url );
               update_option( 'siteurl', $mh_new_site_url );
   
               restore_current_blog();
   
       }
       ```
   
 * If anything goes wrong then via your file management tools your host provided
   you with delete the new plugin file.
 * The gist of that is at this link and might be easier to read or copy.
 * [https://gist.github.com/jdembowski/f223e46741a7be84bec1](https://gist.github.com/jdembowski/f223e46741a7be84bec1)
 * When a new blog is added into a network, if the siteurl and home options are `
   http://` then this will replace that to `https://` instead. Except for when a
   blog is added to your WordPress network, this plugin will not be used.
 * I tested with Microsoft Edge as the browser because Chrome would switch to `https`
   no matter how much harsh language I used.
 * For my test the whole network was http only and my first site was and remains
   http. I copied the plugin into my `mu-plugins` directory and created new sites.
 * The new sites have an https URL for their siteurls and home options (the old 
   sites are untouched). I then uploaded via the media library in the new site and
   that generated media URLs with https.
 * I did the same tests with the original site using http (I logged out, cleared
   my cookies and logged into the old http site). The media for that http only site
   was http and not https as expected.
 *  Moderator [Bet Hannon](https://wordpress.org/support/users/bethannon1/)
 * (@bethannon1)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934219)
 * Jan, you rock! This is cool!
 * I’ll be interested to hear if this works for you, webtechIMT & ncsumarit!
 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [10 years, 3 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934220)
 * Thanks. 😉
 *  Thread Starter [webtechIMT](https://wordpress.org/support/users/webtechimt/)
 * (@webtechimt)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934222)
 * Thanks 😉
 * Is there any core developers to add this in the WordPress core ?
 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [10 years, 3 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934223)
 * I don’t think this _should_ be added to core. It doesn’t perform any checks (
   though I have an idea about that, to check if the right vhost replied and check
   if the X.509 cert is valid before changing the `http:` to `https:`).
 * When you look at the source code for `install_blog( $blog_id, $blog_title = '')`
   you see that WordPress tries to figure out the scheme.
 * [https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/ms-functions.php#L1347](https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/ms-functions.php#L1347)
 * If it sees `https:` then you should get that site URL. On my installation it 
   doesn’t do that and I’m pretty sure it’s because I messed up somewhere.
 * To further complicate things, some browsers make me want to throw heavy objects
   at it. My Chrome browser sees a site and decides to switch to `https` regardless
   if I want it to or if there’s even a site there that accepts `https`. That’s 
   why I had to test with Microsoft Edge as my browser.
 * If I can figure out how to test (I want to mess with `send_headers()` and the
   WP HTTP API) I’ll update the gist so that the site URL and home only get updated
   if WordPress can figure out if the site has a valid cert and is setup to reply.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘How make WP multisite create sites in https’ is closed to new replies.

## Tags

 * [HTTPS](https://wordpress.org/support/topic-tag/https/)
 * [SSL](https://wordpress.org/support/topic-tag/ssl/)

 * In: [Networking WordPress](https://wordpress.org/support/forum/multisite/)
 * 13 replies
 * 4 participants
 * Last reply from: [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/how-make-wp-multisite-create-sites-in-https/#post-6934223)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
