Technical Recipes

How to customize your WordPress server

1 Give its own directory outside the WordPress core installation

   1.1 Move the WordPress core files to a sub-directory from the root installation
    - In the admin panel, change WordPress address (URL) to the new directory, say: http://example.com/wordpress
        Keep the Site address (URL) as: http://example.com
	- Move the WordPress core files to the new location: /wordpress
	- Copy the index.php and .htaccess files from the WordPress directory into the root directory
	- Change the index.php from
	require('./wp-blog-header.php');
	 to the following, using your directory name for the WordPress core files:
	require('./wordpress/wp-blog-header.php');
	- Log in to the site: http://example.com/wordpress/wp-admin/
   1.2 Move the WordPress content from sub-directory to root
	- In the admin panel, change Site address (URL) to: http://example.com/
	-  Copy the index.php and .htaccess files from the WordPress directory into the root directory
	-  Edit your root directory's index.php
	require('./wordpress/wp-blog-header.php');
	- Log in to the site:
	http://example.com/wordpress/wp-admin/
   1.3 Move the whole installation to a different sub-directory 'blog'
	- Add the following to the .htaccess file under root:
		RewriteEngine On
	RewriteCond %{HTTP_HOST} ^(www.)?YourDomain.com$
	RewriteRule ^(/)?$ blog [L]
	
	Now when users to go your root domain (yoursite.com), it will automatically redirect to the subdirectory you specified. When you want to redirect to a new subdirectory, such as the conference site for next year, just update the .htaccess redirect code.

2 Modify the wp-config.php file
 
   For whatever reason, especially for backup and updating, you may want to separate your
   2.1 Set the URL for the WordPress installation
    define( 'WP_SITEURL', 'http://example.com/wordpress' );
 
   2.2 Set the URL for the website home
    define( 'WP_HOME', 'http://example.com/wordpress' );
 
   2.3 Move wp-content folder
        Move the wp-content directory, which holds your themes, plugins, and uploads, outside of the WordPress application directory.
        - Set WP_CONTENT_DIR to the full local path of this directory
    define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/blog/wp-content' );
        - Set WP_CONTENT_URL to the full URI of this directory
    define( 'WP_CONTENT_URL', 'http://example/blog/wp-content' );
   2.4 Move the plugin folder
        - Set the WP_PLUGIN_DIR to the full local path of the uploads directory
    define( 'WP_PLUGIN_DIR', dirname(__FILE__) . '/blog/wp-content/plugins);
        - Set WP_PLUGIN_URL to the full URI of this directory
    define( 'WP_PLUGIN_URL', 'http://example/blog/wp-content/plugins' );
   2.5 Move the uploads folder
        - Set the UPLOADS to the full local path of the uploads directory
    define( 'UPLOADS', '/blog/wp-content/uploads' );
        This path can not be absolute. It is always relative to ABSPATH 
 
 3 An practical example
 
    For whatever reason, especially for future backup and update, you may want to have your own files store in a separate folder other than the WordPress installation folder. Here is how you can do it easily:
 
   3.1 Install the WordPress under /htdocs/wordpress
		Extract the zip file to /tmp and copy or move the complete /wordpress folder to /htdocs
   3.2 Create your own blog folder to store the wp-content
		Copy /wordpress/wp-content to /htdocs/blog
   3.3 Modify the Site address (URL) from the admin panel: Settings
		Site Address (URL): http://localhost/blog
   3.4 Modify wp-config.php
		In addition to the database information, add the following lines into wp-config.php
    	define( 'WP_SITEURL', 'http://localhost/wordpress' );
    define( 'WP_HOME', 'http://localhost/blog' );
    define( 'WP_CONTENT_DIR', '../blog/wp-content' );
    define( 'WP_CONTENT_URL', 'http://localhost/blog/wp-content' );
 	
    Now if you download new themes and plug-ins, they are all saved to the /htdocs/blog folder instead of /htdocs/wordpress folder. It's easy for maintenance and backup.