Moving WordPress from a Subdirectory
-
I have setup a new wordpress site in a subdirectory of my site.
Ex. http://www.mysite.com/wordpressI have the new site ready and want to move it to the root directory so that /wordpress does not show in the url.
Do I just copy all of the files in the wordpress directory to the root or is there an easier way to do this?
-
The easiest way is as follows:
TELL APACHE WHERE WORDPRESS IS
WordPress address (URL): http://example.com/wordpress
Website address (URL): http://example.com
1. Copy the index.php and .htaccess files from the /wordpress directory into the root / directory of your site (Website address)
2. Edit /index.php and change the line that says:
require(‘./wp-blog-header.php’);
to:
require(‘./wordpress/wp-blog-header.php’);
3. Login to /wp-admin and update permalinks and saveDo I just copy all of the files in the wordpress directory to the root
No. You can do that, if you wish, but you would first re-save Settings > General for the new URL. The very simplest thing to do, however is to leave all of that alone and just redirect your domain to WordPress right where it is:
# BlueHost.com # .htaccess main domain to subdirectory redirect # Do not change this line. RewriteEngine on # Change example.com to be your main domain. RewriteCond %{HTTP_HOST} ^(www.)?example.com$ # Change 'subdirectory' to be the directory you will use for your main domain. RewriteCond %{REQUEST_URI} !^/subdirectory/ # Don't change the following two lines. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Change 'subdirectory' to be the directory you will use for your main domain. RewriteRule ^(.*)$ /subdirectory/$1 # Change example.com to be your main domain again. # Change 'subdirectory' to be the directory you will use for your main domain # followed by / then the main file for your site, index.php, index.html, etc. RewriteCond %{HTTP_HOST} ^(www.)?example.com$ # use index.php for WordPress #RewriteRule ^(/)?$ subdirectory/index.html [L] RewriteRule ^(/)?$ subdirectory/index.php [L]Forgot to include – you need to update the site URL and home url in settings -> general before step 3
Thanks for the replys. My site is hosted with Yahoo and there is no .htaccess file.
I changed the following settings in WordPress:
WordPress address (URL): http://example.com/wordpress
Website address (URL): http://example.comI then edited index.php and changed the line that says:
require(‘./wp-blog-header.php’);
to:
require(‘./wordpress/wp-blog-header.php’);Now the sites homepage loads but all of the links are broken.
It just says “404 – Not Found”Is there something else I need to do?
If you have access to phpMyAdmin, you can edit these lines to reflect your own table_prefix in place of ‘pref’ and to use your own old and new URLs, and then run those edited lines as SQL to search your database and replace all instances of the old URL with you new one:
UPDATE pref_options SET option_value = replace(option_value, 'http://www.olddomain.com', 'http://www.newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE pref_posts SET guid = replace(guid, 'http://www.olddomain.com', 'http://www.newdomain.com'); UPDATE pref_posts SET post_content = replace(post_content, 'http://www.olddomain.com', 'http://www.newdomain.com');* note: Change above ‘pref’ (three places) to correct table_prefix and change old and new URLs (three places each and no trailing slashes)
If you do not have access to phpMyAdmin for editing your database directly, I believe there are plugins that can do that and run those same lines.
I do have access to phpmyadmin but am not real familiar with it.
I see that all the table prefixes begin with wp_Would I just run the following on the SQL tab?
UPDATE wp_options SET option_value = replace(option_value, 'http://www.mysite.com/wordpress', 'http://www.mysite.com') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET guid = replace(guid, 'http://www.mysite.com/wordpress', 'http://www.mysite.com'); UPDATE wp_posts SET post_content = replace(post_content, 'http://www.mysite.com/wordpress', 'http://www.mysite.com');If I do this do I still need to make the changes mentioned above?
Thanks!You have the right idea, but I do not think ‘http://www.mysite.com/’ is your actual URL. Also, it is never a good idea to post your table_prefix publicly…and neither is it all that great to have the default ‘wp_’ running anyway. So overall, I would first make an “export all tables” backup of your database, then run the SQL with the actual old and new URLs, then do another backup and then change your table_prefix…and there is more than one way to do that. Some plugins can do that from your Dashboard, and I use BulletProof Security for that since I already know it gets all the fine details exactly right.
I just used mysite.com as an example. I would replace that with my actually domain.
I will give it a shot. Thanks!I moved all of the wordpress files to the root directory and ran the updates on the database.
The homepage loads but all of the other pages still come up with 404 not found error.
If I change the permalinks to the default settings the pages do load correctly with the id’s but I cannot get the permalinks to work right. Is there anything else that would cause this?Doing that will fix the old issue but create a whole new world of new issues.
what are your site URL and home URL in Settings -> General
They are both the same after moving the files into the root:
WordPress address (URL): http://example.com
Website address (URL): http://example.comI spoke with Yahoo and they said WP must be installed in a subdirectory.
They do not allow an .htaccess file so the subdirectory shows in the URL for all pages.
Ex. http://example.com/wordpress/contactI spoke with Yahoo and they said WP must be installed in a subdirectory.
…the subdirectory shows in the URL for all pages.
Ask them specifically about assigning your domain to that sub-directory so that folder name does not have to be part of your domain URL to get there. At my own host, a primary domain *cannot* be assigned to a sub-directory such as your host requires, and I use that .htaccess so I *can* have it there anyway. Overall, however, it is difficult for me to believe your host has things configured so that you *must* have that folder name in your URL.
What happens when you change the WordPress address (URL) to: http://example.com/wordpress
I ended up having to keep everything in a subdirectory in order for the site to work.
So I am back to the following settings:
WordPress address (URL): http://example.com/wordpress
Website address (URL): http://example.com/wordpressI am just stuck with /wordpress in the url. Yahoo told me there is nothing they can do about this. I think the only solution is to switch hosts.
Somewhere I once saw something about making that *look* different in a browser address bar, but you have no .htaccess (as I recall) and that would not change the actual access URL anyway.
I think the only solution is to switch hosts.
Possibly. Different hosts have different configurations where some assume/require specific assignment to a given “site builder” or whatever of their own.
The topic ‘Moving WordPress from a Subdirectory’ is closed to new replies.