Giving WordPress its own directory while leaving your blog in the root directory
WordPress, SandboxBlogger April 4th, 2007Typically, when I install Wordpress, I usually install it in the root directory of the website. That is because I prefer not to host too many things under one domain name and I really don’t like overly long URL. Simply put, I like my blogs accessible via URL like http://example.com/ rather than http://example.com/my-wonderful-blog.
Installing Wordpress in the root directory of the website is usually not a problem but really soon, I would start to optimize my blog for search engine and usually means, placing files like robots.txt, and sitemap.xml. Add a .htaccess file to support the customize the URL. Then there are files for ownership verification required by services like Yahoo! Site Explorer to help clutter up the root directory even more. That is all fine until one day a new version of Wordpress is released and it is time to upgrade (just like TODAY!)
Every time I need to upgrade, I find myself doing a lot of cross referencing to make sure I’m not deleting the wrong files. This time around, when I’m installing Wordpress for SandboxBlogger.com, I’ve came across this instruction on the Wordpress.org. What a great idea! Basically, this simple guide showed me how to install Wordpress in a subdirectory off the root directory of the website yet the URL will still remain as http://www.example.com/. Also, all other files I place in the root directory of the website is still accessible via URL like http://www.example.com/sitemap.xml.
For those interested, here’s how:
- Unzip wordpress package in the root of your website. Assuming the root of your website is ~/public_html/, you will now have ~/public_html/wordpress (wordpress unpacks into a subdirectory named wordpress). Move the wordpress directory to another directory name like myblog. I assume you will want to but if you don’t, remember to substitute myblog to the actual directory name you want to use.
- Proceed to install Wordpress as the installation guide said and use this URL: http://example.com/myblog/wp-admin/install.php. Your blog will now have the following URL http://example.com/myblog/.
- Login and go to the Options panel.
- In the box for “WordPress address (URL):” you should see http://example.com/myblog/ leave that alone.
- In the box for “Blog address (URL):” change the address to the root directory’s URL, like http://example.com/. Click on the picture below to see where in the Wordpress Dashboard to make the changes.
- From the file system, copy index.php from ~/public_html/myblog/index.php to ~/public_html/index.php.
- Open the ~/public_html/index.php file in your text editor and change the following line:
require(’./wp-blog-header.php’);
to the following:
require(’./myblog/wp-blog-header.php’); - If you need to customize your permalink, remember to create your .htaccess file in ~/public_html/.htaccess
Remember to also place all other files that do not belong to Wordpress in ~/public_html/. Example files like robots.txt and sitemap.xml.

October 6th, 2007 at 5:09 am
I’m currently applying this tutorial to my blog. Two problems I’m having are what are all the necessary files that I need to move? and the .htaccess can be created like any file? Do I create a blank file named .htaccess? I don’t see a notify me of comment button. Can you email me once your reply please?
October 8th, 2007 at 5:15 am
Hi Alex,
There is really no files you need to move unless you want to install WordPress in a directory other then …/public_html/wordpress. To minimize confusion, replace all “myblog” with “wordpress” in the tutorial. One thing to remember, in the tutorial, public_html is the directory where it is the root of your site. Meaning that if you place a file call “pictures.html” in the public_html directory and your site is example.com, then you can access the file with this URL: http://example.com/pictures.html
The other two files that are required to be in the root of your site are the index.php and .htaccess. But instead of moving the index.php, you will want to copy that file from public_html/wordpress/index.php to public_html/index.php.
As for the .htaccess, when you customize the url of your blog in the “Options | Pemalink” page, you are given the content of the .htaccess file after you have save the options. Just create the .htaccess with what WordPress has provided. Unless if you want to let WordPress handle that .htaccess file, just create an empty file and set the permission to allow access to everyone. I personally would just create that file with what WordPress provide.
Hope that helps.
BTW, if you want to keep track of the comment on this blog or want to get notified of reply to your comment, you can always subscribe to the comments RSS feeds. The link is at the bottom of the footer on this page.
October 26th, 2007 at 10:21 am
What about an existing site that was already installed and running on a sub directory (myblog in you example) …
Can I now go back and change the options as above to make the blog appear as if it was on the root?
Will all my old posts be ok?
October 26th, 2007 at 5:49 pm
Hi Doug,
For existing users, it makes no difference and the move is relatively easy. Just copy or move those files and make the configuration changes as in the guide.
October 28th, 2007 at 11:01 pm
hi, i tried the tutorial for giving wordpress a new directory. this is what i did and what happened to me:
1. i have my blog at http://example.com/wp
2. i went to options, change the blog url to example.com
3. i have only my .htaccess at my root directory so what i did was move the index.php file from public_html/wp to public_html.
what happened is that i cannot access my example.com and example.com/wp anymore; i get a 500 internal server error.
4. i tried moving back the index.php to public_html/wp but still same error.
what should i do?
October 28th, 2007 at 11:07 pm
oh, nevermind. i found out what happened. this is what did:
1. after i returned the index.php to public_html/wp, i then “copied” (not “move” anymore like i did the first time) index.php to public_html.
2. i edit public_html/index.php and changed the require(’./wp-blog-header.php’); to require(’./wp/wp-blog-header.php’);
3. i still got the same 500 internal error, so i tried checkin the contents of my public_html/.htaccess and i saw that there was only two lines added ” # BEGIN WordPress
# END WordPress”
4. so what i did was remove that two lines and saved my .htaccess and when i tried typing my example.com url, my blog already showed! yey!
October 29th, 2007 at 2:42 am
kuting,
I’m glad you have solve your problem but it seem strange the two lines in the .htaccess was causing the problem. Just curious, is your hosting service on a Windows server?
February 20th, 2008 at 1:46 pm
If I currently have the Wordpress URL as www.michaelaulia.com/blogs and want to change so that it becomes:
www.mihcaelaulia.com to access Wordpress, will the old link still work (../blogs/my-post.html) after I change the option?
February 20th, 2008 at 3:01 pm
Michael,
Interesting question. I’ve not tried it myself but I suppose it should work (Err… I mean I don’t remember). I’ll give it a try later and update the post. If you decide to try the move before I have a chance to try it out, please make sure you have your blog backed up before attempting the move.
February 21st, 2008 at 12:04 am
Michael,
OK, I’ve had a quick test and unfortunately no, old link will not work without some .htaccess magic. If you need help with that, just let me know. I’ll probably write a post about it over the weekend.
EDIT: OK, apparently it works. I don’t know why it did not work the first time I’ve tried it but it works. I’ve tested with WordPress 2.3.3 and by changing the blog location, WordPress will redirect your old link to the new link. The only exception is WordPress will not handle the home page. e.g http://example.com/blog will give you a 404 error after the move from http://example/blog to http://example.com.
February 21st, 2008 at 7:07 am
Ah I see! Really appreciate you for trying it out just for me!
I’m still in the dillema whether to keep my blog as /blogs (already have good traffics) or move the URL to my root domain *ugh*
February 22nd, 2008 at 4:51 am
Michael,
Although I would love to seize the opportunity to do some PR, I’ll have to be honest. I’m such that I must find answers to burning question in my mind. However, you are the one who have put it there, so I’d have to try it out so that I can answer it for you too.
As for the question of whether to move your blog or not, I have the following to say. The usual reason why one would want to move a WordPress installation to a subdirectory is for reason of easier upgrade procedure. On the other hand, to configure WordPress to serve the blog from the root is mostly a matter of preference. Although some may argue that moving the blog to the root of the site is better for SEO but I’ve seen the same argument to keep the blog in a subdirectory call /blog/. I’ve also seen very successful blogs that are configured to live in root as well as in a subdirectory /blog/. So, to go with root or /blog/, it is really not a huge factor as to whether the blog is going to be successful or not.
If your blog is new and you are asking whether to move or not, I would say go ahead if that’s your preference. However, I would say think twice if your blog already have good traffic and if readers are able to find your blog’s URL by going to the main page of your blog.
I hope the above will point you in the right direction.
February 22nd, 2008 at 6:13 am
Hey, cheers very much for that, Han. I honestly don’t want to move my blogs cause it has 200 unique traffics a day (I know it’s not much yet, but it’s something)
I’ll reconsider moving it to “blog” (I don’t know why I even put ’s’ at the back *Doh!!*) and probably setup a 301 to it (need to google a bit first)
Thanks again, you don’t how many times I’ve refreshed your page
February 22nd, 2008 at 2:43 pm
Michael,
If it is up to me, I’ll say don’t change. As for moving from /blogs/ to /blog/, I’d say change only if you have a lot of 404 from people typing in …/blog on the address bar. If you don’t get a lot of that, there is little point changing. I don’t really see the difference between /blogs/ and /blog/.
So you are the one skewing my stats! Haha…
February 25th, 2008 at 8:04 am
LoL Thanks for that Han
I’ve decided not to changet anything, but put an index.html under /blog/ that forwards to my blogs
February 25th, 2008 at 3:31 pm
Micheal,
That’ll work too.
March 9th, 2008 at 4:11 am
Hey, I was wondering if you could help me out with something. I managed to successfully do this process from mobilegreen.org/blog to mobilegreen.org, but for some reason when I go to www.mobilegreen.org, I only have a blank page! Any help would be much appreciated.
March 9th, 2008 at 4:12 pm
Hi Ko,
It looks like something you did cause an error. The question is what did you do different or what is different in your environment. By looking at your blog, there is no indication of what is the cause because there is absolutely nothing in that page. Please read through the tutorial again and point out anything you may have done differently. Also, is this is your initial installation or you have a blog going and you are trying to move the url?
The other thing to look out for is, do you have any stray files in your installation? Example, do you have index.html in your web root? If so, check if those files could cause the problem you are seeing.
April 1st, 2008 at 12:17 am
hi. great info here! thanks!
i am just in process of setting up my wordpress blog and i would like it to be what people see first when they go to www.kpphotography.ca
my problem is that i don’t have an .htaccess file…. at least not that i can see. and i’m not sure if i am understanding your instructions in comment #2.
“As for the .htaccess, when you customize the url of your blog in the “Options | Pemalink” page, you are given the content of the .htaccess file after you have save the options. Just create the .htaccess with what WordPress has provided. Unless if you want to let WordPress handle that .htaccess file, just create an empty file and set the permission to allow access to everyone. I personally would just create that file with what WordPress provide.
Hope that helps.”
where do you see the contents of the .htaccess file? i’m not seeing that.
April 1st, 2008 at 12:38 am
Hi kathy,
The .htaccess content can be seen when you go to “Options | Permalinks”. You need to scroll to the bottom of that page. If you don’t have that file writable by WordPress, you need to create that file in the root of your blog and paste the content you find from the WordPress options page as mention above.
April 1st, 2008 at 1:08 am
thanks han! and i’m sorry to be such a bother, but what exactly will that content look like? is it the info that is in the ‘custom structure’ box?
when i created the .htaccess in the root of my blog, i got an error page.
i’m so confused by this.
April 1st, 2008 at 1:23 am
i just figured it out!
thanks so much for your kind help!
have a GREAT day!
April 1st, 2008 at 4:04 am
kathy,
It’s not the ‘custom structure’ box. It’s the box at the bottom of the page, but you already knew that.
Glad you have figured it out. You have a great day as well and happy blogging.
August 9th, 2008 at 5:39 am
hello,
i installed the WP 2.6 at the directory (instead of the root) using fantastico install and changed the blog url to reflect the main url. i also changed the index.php as per instruction. as i cannot directly copy it, i uploaded the edited index.php via filezilla to the public htlml folder. i cannot see the ht access file from the directory folder, but it is in the root folder. When i view site, it is showing the hosting provider? I do not know how to figure it out as this is my first time to install WP.
Your help will be appreciated.
August 9th, 2008 at 6:37 am
Further to my question, basically how do you COPY the index.php and .htaccess files from the WordPress directory into the root directory of the site? In my case, I did not see any .htaccess files from the subdirectory, the file is already in the public_html. I am getting error messages..
August 14th, 2008 at 4:31 am
Hi vi,
What you need generate the .htaccess before setting the blog address. The easiest way to do this is to change permalink. If you have the right permission, it will be updated for you. If not, WordPress will show you what to do.
To change permalink login to the admin panel and go to the “Settings” tab. Next, click on “Permalinks” to change your permalink. You can pick either one of the pre-defined link format or “Custom Structure” and customize it how ever you like. If you don’t have the right permission on that directory (99.999% of the case), WordPress will show a text box at the bottom of the “Permalinks” page once you have save your new permalink format. In that case, you will need to copy the text in the textbox and create the file on your computer. You can now upload the .htaccess instead of copying over.
Alternatively, you can also open up the .htaccess with cpanel in your public_html directory and modify it based on WordPress suggestion above.
If in the event that you do have the right permission to create the file via WordPress, then you can continue with the rest of the guide and copy the .htaccess file to the correct location.
Hope that helps.