I was in the need to have multiple domains run from a single install of WordPress but wanted them to have their own database.
WordPress has a nice multi-site system but I am not working on subdomains and I don’t care for a network.
I did some searches on google and never found anything really useful so I created a quick script to handle the multiple domains on a single install.
To install the script:
Edit your wp-config.php, add this code to the top of the file:
/**
* WordPress Multiple Domains
*
* Loads configs based on domain
* If no config is found initial WordPress install is used
* Config files are stored in '_domains' in the WordPress directory
* Config naming convention: {$domain}_wp-config.php
* $domain does not use www.
*
* @package WordPress
* @author Jeremy Simkins
*/
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
$website = strtolower(str_replace('www.', '', $_SERVER["SERVER_NAME"]));
$website = preg_replace('[^a-z0-9\.-]', '', $website);
// Check if there is a domain config
if (file_exists(ABSPATH . '/_domains/'.$website.'_wp-config.php')) {
require_once(ABSPATH . '/_domains/'.$website.'_wp-config.php');
unset($website);
return; // Step out of file
} // If no config is found, defaults to initial install (could throw an error if forced to use this method)
unset($website);
// End - WordPress Multiple Domains
In your WordPress directory (same as wp-config.php), create a directory named: _domains. Store all domain configs in this directory to have multiple domains run from a single install of WordPress. When saving the configs to the domains folder, make sure to name them using the naming convention in the above snippet.
It’s a pretty simple script, hope you find this useful.
I did want to make note on one issue that I haven’t worked out yet. This would be the uploads directory. I am not sure if this is even an issue yet but it seems possible… There may be a chance of upload collisions between the sites. For development this is not an issue (at least for me) but on a site in production this could be catastrophic.
Update:
I did find out that the media manager does not conflict. There seems to be no issues with running multiple installs using this method.
There isn’t much to say about this… I am developing a new system that uses jQuery DataTables and I needed to be able to disable a row from sorting without having to build unique js for each table. I wrote this script whichs works perfect for my needs. It may need to be tweaked to work with your tables but it should get the job done.
How the script works:
First it finds each table setup to use DataTables [in my case I am using classes ('.dataTable .table') because not all tables will implement DataTables].
It will build an array of dontSort with each table id in it (make sure you are using the id attribute in your table).
It will then process each th in the thead to see if a no-sort class exists. If the no-sort class exists, it will disable sorting for this column.
var dontSort = [];
$('.dataTable .table').each(function () {
var tmpID = this.id;
if (dontSort[tmpID] === undefined) {
dontSort[tmpID] = [];
}
$('#'+tmpID+' thead th').each(function () {
if ( $(this).hasClass( 'no-sort' )) {
dontSort[tmpID].push( {
"bSortable": false
} );
} else {
dontSort[tmpID].push( null );
}
} );
} );
for (var tmpID in dontSort) {
$('.dataTable #'+tmpID).dataTable({
"aoColumns": dontSort[tmpID]
});
}
Pretty simple and easy to modify. Let me know if you have any questions.
With SEO being an important factor in wed design, it is recommended to use either WWW or non-WWW for your site URL; it is not wise to use both. This can easily be done by using .htaccess. There are situation when using .htaccess is not possible and the only means to do the redirect is by using PHP. I have recently found myself in this situation and I decided to post this simple code snippet that will redirect non-WWW URL’s to the WWW URL.
The code is:
// Check if we need to perform a redirect
$fetchedURL = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
if (substr($fetchedURL,0,4) != 'www.') { // Make sure the URL does not use www.
// Let do the redirect
header( "HTTP/1.1 301 Moved Permanently" );
header('Location: http://www.'.$fetchedURL.((isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : '')); // Append the REQUEST_URI
}
The code is very simple and is documented. I hope some may be able to make use of this script.
The above code will take the provided URL and forward it to the WWW URL. This will retain the full URL path. I.E.: http://son9ne.com/index.php?somevar=somevalue will be changed to http://www.son9ne.com/index.php?somevar=somevalue
I work on many sites and some of my databases are too large to upload with phpMyAdmin. One of the biggest issues I have had was trying to import a large database into MAMP or take a large database out of MAMP and put it live. Another problem is when I am changing computers or restoring my Mac it is much easier to use Time Machine and grab these files instead of having to create a backup and re-import them. After failing on many searches on Google I finally found out where MAMP stores the DB files.
The path you can find these files is:
/Library/Application Support/living-e/MAMP PRO/db/mysql
For the latest version of MAMP Pro (currently 1.8.1):
/Library/Application Support/appsolute/living-e/MAMP PRO/db/mysql
I assume that if you are running MAMP Pro, you would only need to amend the path to MAMP if not.
Well i was trying to find a way to remove all the .svn files from a directory on OSx.
I found this code worked the best for fully removing all .svn files recursively.
find . -name .svn -print0 | xargs -0 rm -rf
Remember to cd to the directory you are wanting to remove the .svn files from.
cd Sites/project
It seems some are having trouble setting up the Zend Debugger so i wrote this after doing some testing to see why people are having this problem. I provide below how to do this in MAMP Pro. This will also get rid of the :8888 at the end of the url as well.
Click to continue reading “Setting up MAMP Pro with Zend Debugger, Optimizer and Extension Manager”
It seems some are having trouble setting up the Zend Debugger so i wrote this after doing some testing to see why people are having this problem. I provide below how to do this in MAMP. This will also get rid of the :8888 at the end of the url as well.
Click to continue reading “Setting up MAMP with Zend Debugger, Optimizer and Extension Manager”
Click to continue reading “Windows XP SP3 breaking Microsoft Updates fix”
Well,
After playing with sweetcron for a bit I wanted to have 4 sites use it but I didn’t want to have to update each site everytime I need to update sweetcron. I found a little tweak you can do to get sweetcron working on multple domains with one install.
Click to continue reading “Use one SweetCron install for multiple domains”