My site uses WordPress as a CMS and it’s installed in a subfolder already but I set it up to display on the root domain. Basically, example.com displays the contents of example.com/wordpress.
The old (static) website was also in a subfolder and I need to redirect that entire subfolder (folder and all contents) back to the root – e.g. point example.com/oldwebsite to example.com.
I’ve tried lots of different approaches and I just can’t get it to work.
The following solution is quite simple to implement. What you get is:
Remarks
What you need to get this working:
Edit /index.php
you need to add the subdirectory to your wordpress installation to the path
Edit /.htaccess
replace /wp/ with the name of the directory where you installed wordpress
WordPress settings
Renaming the wordpress directory
This is a case study of which I recently moved from a sub-directory (/wordpress) to the root directory (/).
You can get some interesting tips by reading this or better still, assign the move to us at a nominal cost and save yourself all the hair-pulling 🙂
Step 1: The site was on Cpanel, so I took a full backup of the site to avoid chances of a major disaster happening if something went wrong (you know the Murphy’s laws, don’t you?).
Step 2: I upgraded the current blog (at /wordpress) to the latest version so that the database structure will be up to date.
Step 3: I downloaded all the files in the root directory to a local folder so that I can replace the overwritten files, if any are required.
Step 4: I then uploaded a full copy of the blog software to the root directory (public_html folder as this was a cpanel site). If there are any special plugins used, you should download the software from the previous location and then upload this in the new location so that the plugin files are also uploaded.
Step 5: I uploaded the wp-config.php fie in the root directory so that WordPress will refer to the same database.
Step 6: I accessed the database through PHPmyadmin and opened the wp_options table. Updated the values of the site_url and home options to http://www.domain.com by replacing http://www.domain.com/wordpress.
Step 7: Now I accessed the blog through the root URL and it opened fine. However I noticed that the posts were still being linked to http://www.domain.com/wordpress/postname/id.
Step 8: I accessed the admin console and recreated the Permalinks so as to update all the post URLs.
Now the whole blog was working fine without any issues.
Lastly, I needed to make sure that Google and other search engine would redirect the old indexed /wordpress/post URLs to the new ones. For this, I edited the .htaccess file in the root directory.
Inserted the following code before the # BEGIN WORDPRESS section (if you don’t keep this code out of the WORDPRESS section, WordPress will remove this when you update Permalinks or do any other act that works with .htaccess file).
RewriteEngine On
RewriteBase /
rewriterule ^wordpress(/.*)? $1 [L,R=301]
This effectively creates a permanent redirect for all files with /wordpress/something name to /something names.