How to make a single WordPress install work on Multiple URLs

How to make a single WordPress install work on Multiple URLs. Handy if you have a shared SSL certificate.

If you have a wordpress website at http://example.com and your hosting provider gives you a shared SSL link https://ssl.your-example-host.com/~example/  then you will notice that wordpress doesn’t work very well on the shared SSL link.

This is how to fix it! It requires modifying the wp-config.php – this is because other methods (eg: writing a plugin or sunrise.php) do not work before WP_CONTENT_URL is defined. 

Open your main wordpress wp-config.php file from FTP, and paste the following code after the first line with <?php on it.

Make sure you change the bold bits to the website addresses you want to use wordpress on! 

/******* START CUSTOM CODE *******/
        $valid_urls = array(
                "http://example.com/",
                "https://other-example.com/",
                'http://another-example.com/test/',
        );
        $ishttps=false;
        if ( isset($_SERVER['HTTPS']) ) {
                if ( 'on' == strtolower($_SERVER['HTTPS']) )
                        $ishttps=true;
                if ( '1' == $_SERVER['HTTPS'] )
                        $ishttps=true;
        } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
                $ishttps=true;
        }
        $this_url = 'http'.($ishttps ?'s':'').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

        foreach($valid_urls as $url){
                // chceck if this is right.
                if(preg_match('#^'.preg_quote($url,'#').'#i',$this_url)){
                        define('WP_CONTENT_URL',$url.'wp-content');
                        define('WP_SITEURL',$url);
                        define('WP_HOME',$url);
                }


        }
/******* END CUSTOM CODE *******/

Leave a Reply

Your email address will not be published. Required fields are marked *