• Moving Wordpress to its own directory, without getting errors

    Posted on Jan.22, 2009 » by Dean

    Many times your website hosts a blog along with other PHP scripts, or static pages. To manage clutter, it is best to put each script in its own directory and keep the root clean. 

    In this blog, I am talking about a special case – If you want to move wordpress to its own directory of your domain, but still want to access the blog from root http://www.yourdomain.com.

    Though there’s an option to run wordpress from its own directory in admin panel, it took me some time to get it right. Here’s the process that i followed, sequentially, so that there are no errors while moving wordpress to its own directory.

    1. Install the wordpress from subfolder 

    Create a folder say wordpress in your domain’s root, and install wordpress from it using the famous 5 minute install process. Once done, your wordpress should run smoothly from say http://www.yourdomain.com/wordpress. Directory’s name need not be wordpress, it can be anything – blog, wp or anything you fancy.

    2. Moving index.php 

    Now, Copy the index.php from wordpress folder and paste it in the domain root. You’ll also need to edit the following code line to match your wordpress’ installation folder. 

    require(’./wp-blog-header.php’);

    to the following, using the directory name for the WordPress files:

    require('./wordpress/wp-blog-header.php');

    3. Changing the Admin option

    Since the index.php is left intact in the wordpress folder, you can still login to to Admin Panel just like before.

    Go to Settings > General, and change the Blog address url from http://www.yourdomain.com/wordpress to http://www.yourdomain.com, and click on Save Changes.

    wp-homeurl-changed

    4. Test the changes

    Click on “Visit Site”, from the top of the website. It should take you to http://www.yourdomain.com now. If everything is working fine, you may want to remove the index.php from wordpress folder or atleast comment all the content inside.

    Removing index.php may allow viewing the directory index, depending on your server configuration.

     

    This change allows you to access your website from domain root, but the wordpress admin panel will still be accessible through wordpress folder – e.g. http://www.yourdomain.com/wordpress/wp-login.php.

    A word of Precaution

    Though there’s no rocket science in doing so. But to err is human. 

    You should backup the Wordpress DB before attempting this, if you have an existing blog. For advanced users, it may help to know that wordpress’ home url is stored in “wp_options” table, with option_name “home” as of wordpress 2.7. There’s another option in wp_options table – “siteurl”, that stores the address where wordpress’ actual files are located.

    Tags: ,

    This entry was posted on Thursday, January 22nd, 2009 at 2:23 pm and is filed under Blog Tips. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.
  • One Response

     

    1. Jan says:

      One nice day I moved my website (not the one linked from my name) from one hosting to a dedicated server. All went nicely except for WP MU. I used the same structure of directories, exported and imported the database. Everything looked perfect. Except for logging onto accounts, creating new blog accounts, working within admin panels of existing users. So, another nice idea came to my mind… Let’s keep the database, install newer WP MU. The result? Things got even worse, nothing worked.

      So I don’t use WP MU any longer. The same applies to ordinary WP.

      When it works, then don’t touch it.

      BTW, blogs were just a piece of my site… It’s interesting that all what I’ve coded myself worked 100% on a new server.

      PS: You could install that plugin which notifies commentators about new replies on the topics. I’m wondering what the relies will look like (if any), but I see no way how am going to be informed about them :-S .

  • Leave a Reply

    Let us know what you thought.

  • Name (required):

    Email (required):

    Website:

    Message: