I am moving a brand new WordPress site from root “/” directory to a subdirectory “/wordpress/” using the following guide:
https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
Sadly, there are problems with these steps.
Step (4) indicates we need to update “Site address (URL)” which updates wp_option “siteurl” to “http://localhost/” but will leave “home” in tact (http://localhost/wordpress).
This is causing issues as I can no longer login to wp-admin. By setting both “siteurl” back to “http://localhost/wordpress” I am finally able to access wp-admin, but now the pages are throwing 404’s and cannot be found. Not only that, but all URL’s have /wordpress/ in the path now which isn’t a slug I want in my pages. In other words, I am fine with having wp-admin accessible via http://localhost/wordpress/wp-admin/ but public pages should be accessible using this format: http://localhost/page-1/
Is there a way to move WP to a subdirectory without all these consequences?
Step 1: Export your database as
.sql
open the file using text editor. find thehttp://localhost
and replace withhttp://localhost/wordpress
and again import it. This will work.!Step 2: Update
siteurl
andhome
Next you need to change the location of your site in the database.
In wp_options, locate siteurl and home. Usually these records are at the top of the table on line 1 and 2.
For siteurl, click the field under option_value and replace the old domain with your new domain name.
Press enter to save.
Do the same for home.
Step 3: Fix permalinks (Optional)
If you experience that you get a 404 error when you try to open links on your site, the Permalinks are broken. Luckily it is very easy to fix this.
Log in to your WordPress dashboard.
Click Settings and then Permalinks
Scroll down and click Save Changes.