How to move wordpress to subdirectory - php

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 the http://localhost and replace with http://localhost/wordpress and again import it. This will work.!
Step 2: Update siteurl and home
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.

Related

WP-Admin redirects to old URL (after editing config.php)

I am trying to get a client's WordPress site copied over to my company's server to use as a development site. I've ran into an issue when trying to log into the site's administrator panel; it redirects us to the existing site's URL instead (ending up as [OLD SITE]/[NEW URL]/wp-admin). Additionally, trying to go to any page other than the homepage gets a 404.
I've tried editing the wp-config and defining the WP_HOME and WP_SITEURL there, with no success. In a previous attempt we used a backup tool that was meant to replace references to the old URL with the new URL, and on another we ran queries and checked through wp-options in the database to be sure that we caught all of the old references. Still redirects to the old site.
We've tried restoring from two backups, Akeeba and BackUpWordPress. Our current attempt is a copy we've downloaded directly and then uploaded (with an imported SQL backup).
Another odd thing I've noted is that changing one of the URLs in the database causes more issues. Mainly, if I update the URL of 'wordpress-https_ssl_host' in the wp-options table, the theme breaks. Not sure where to go with this from here.
I'm always succesfully using the following script : search & replace:
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
in order to update a wordpress site url.
Just copy the provided code in a directory under your site, then launch the provided index.php in a browser: the database infos should be automatically determined. Then specify the old and new urls and click on "Run" !
Don't forget to remove the created directory afterwards.
For solving this issue you have to change siteurl in database wp_options table
option_name = siteurl where
option_value = YOUR OLD SITE URL
change your old site url and update it with your local developement site URL
Hope this will help you..
We found the problem; as it turns out it was nothing to do with anything from the default WordPress files. The client was using an extension called WordPress HTTPS, and apparently that was causing a conflict somewhere. We renamed the extension's folder to disable it and everything ran fine. I imagine it was overriding what we were setting in wp-config.

URL redirects to subdomain when updating page from wp-admin

I have site hosted in http://blog.example.com now i have moved it to location http://blog.example.com/myblog folder. Have changed site location from wp-options table and it works fine in new locaiton. but my problem is that when i update any page or post from admin panel, page redirects to http://blog.example.com url. I am not able to update that page.
Note: I have used visual composer for page editor.
Pls suggest me setting that i need to change.
I would make an export of your database and find and replace http://blog.example.com with http://blog.example.com/myblog in your favorite text editor to make sure that all mentions of the old URL have been removed.
Afterwards you can also find and replace http://blog.example.com/myblog/myblog with http://blog.example.com/myblog to change URL's that were already changed back.

WordPress files not seeing /~username/ on localhost

I have a localhost running on localhost/~frederoover/, everything works perfect, but when I install a WordPress website, I'm getting the following issue's.
localhost/~frederoover/agri-travel.be loads just fine, but the internal files all give a 'Failed to load resource: the server responded with a status of 404 (Not Found)' and they are pointing to localhost/wp-content/plugins/*. So WordPress doesn't see my /~username/.
Any thoughts on how to solve this?
Your site URL is incorrect. The easiest way to fix this to add this to your wp-config.php and load the home page:
define('RELOCATE', true);
Make sure to remove it after you are finished.
Step 1: Export your database as .sql open the file using text editor. find the http://localhost and replace with http://localhost/~frederoover/sgri-travel.be and again import it. This will work.!
Step 2: Update siteurl and home
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 ( http://localhost/~frederoover/sgri-travel.be in your case ).
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.

Change URL on Wordpress

I have been working on a WordPress site.
www.example.com and the main homepage of my site(index.html) says "We're under construction etc." and it's just an image.
For the development of the website, I have been using a different directory - www.example.com/dev and everything I have developed has been under /dev(/dev/index.php etc.)
The website is now ready and I need to point the finsihed website (www.example.com/dev) to the actual public site(which is now under www.example.com) that I have finished. How do I go about this?
use this code for changing you website url
SET #oldsite='http://www.example.com/dev';
SET #newsite='http://www.example.com';
UPDATE wp_options SET option_value = replace(option_value, #oldsite, #newsite) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, #oldsite, #newsite);
UPDATE wp_links SET link_url = replace(link_url, #oldsite, #newsite);
UPDATE wp_postmeta SET meta_value = replace(meta_value, #oldsite, #newsite);
This can be done 2 ways,
You can do this easily by changing site_url in options table. Once you transfer data and change the url your site should be running on the new url. If you have stored static urls in post or pages then, you have to change that as well.
Export sql file from phpmyadmin. Now find and replace all urls from old to new ones.
Note: Keep your current development site working as, sometimes it's possible that contact form 7 or any data gets missing. For example, Widgets get in inactive mode sometime.
Once your new website is confirmed then you can remove your old website.
step 1:
Just copy your all files and folder from www.example.com/dev to www.example.com
step 2:
open your database and in table wp_option
siteurl
http:// www.example.com/dev to www.example.com/
home
http:// www.example.com/dev to www.example.com/
Moving Directories On Your Existing Server
Wordpress has a wiki page that explained this for you:
Moving Wordpress
Here are the step-by-step instructions to move your WordPress site to a new location on the same server:
Create the new location using one of these two options:
If you will be moving your WordPress core files to a new directory,
create the new directory.
If you want to move WordPress to your root directory, make sure all
index.php, .htaccess, and other files that might be copied over are
backed up and/or moved, and that the root directory is ready for the
new WordPress files.
Log in to your site.
Go to the Administration > Settings > General panel.
In the box for WordPress Address (URL): change the address to the
new location of your main WordPress core files.
In the box for Site Address (URL): change the address to the new
location, which should match the WordPress (your public site)
address.
Click Save Changes.
(Do not try to open/view your site now!)
Move your WordPress core files to the new location. This includes
the files found within the original directory, such as
http://example.com/wordpress, and all the sub-directories, to the
new location.
Now, try to open your site by going to yourdomain.com/wp-admin.
Note, you may need to go to yourdomain.com/wp-login.php
If you are using Permalinks, go to the Administration > Settings > Permalinks
panel and update your Permalink structure to your
.htaccess file, which should be in the same directory as the main
index.php file.
Existing image/media links uploaded media will refer to the old
folder and must be updated with the new location. You can do this
with the Better Search Replace plugin, WP-CLI's search-replace if
your hosting provider (or you) have installed WP-CLI, manually in
your SQL database, or by using the 3rd party database updating tool
Search and Replace Databases Script * Note: this script is best used
by experienced developers.
In some cases your permissions may have changed, depending on your
ISP. Watch for any files with 0000 permissions and change them
back to 0644.
If your theme supports menus, links to your home page may still have
the old subdirectory embedded in them. Go to Appearance > Menus and
update them.
Sometimes you would need to restart your server,
otherwise your server may give out an error. (happens in MAMP
software (Mac)).
It is important that you set the URI locations BEFORE you move the
files.
If You Forget to Change the Locations
If you accidentally moved the files before you changed the URIs: you have two options.
Suppose the files were originally in /path/to/old/ and you moved them to /path/to/new before changing the URIs. The way to fix this would be to make /path/to/old/ a symlink (for Windows users, "symlink" is equivalent to "shortcut") to /path/to/new/, i.e.
ln -s /path/to/new /path/to/old
and then follow the steps above as normal. Afterwards, delete the symlink if you want.
If you forget to change the WordPress Address and Blog Address, you will be unable to change it using the wordpress interface. However, you can fix it if you have access to the database. Go to the database of your site and find the wp_options table. This table stores all the options that you can set in the interface. The WordPress Address and Blog Address are stored as siteurl and home (the option_name field). All you have to do is change the option_value field to the correct URL for the records with option_name=’siteurl‘ or option_name=’home‘.

Incorrectly Changing WordPress URLs on Same Server

So we have a dedicated server and we installed a single instance of Wordpress on this URL (using URL as example): AnytownBoatTours.com. Started themes and plugins etc... and the owner said the URL needs to be the other way around: BoatToursAnytown.com.
So, we pointed the new domain to existing instance of WordPress (since they are on the same dedicated server), and then I followed wordpress instructions by going into Settings -> General and changed both the Wordpress Address (URL) and Site Address (URL) to BoatToursAnytown.com (with no "/" at ending on either).
So, everything appears to be fine. The Wordpress site seems to have accepted the URL change and I've logged in and made changes to the home page and theme. Then I came across a weird error with sub pages I'd created before the switch. The error occurs in all pages except the home page. When I click on any of the pages except home and edit them, when I hit update or preview buttons, the preview goes to a 404 message. I thought that is weird so I started looking around.
I discovered that the content directory is still pointing back to the old URL. The Wp-config Location is: D:\Websites\AnytownBoatTours.com/wp-config.php and the Content Directory is: D:\Websites\AnytownBoatTours.com/wp-content
So obviously the change in General Settings didn't work. I was hoping someone could help me figure how to go from here.
Thank you
Update your permalinks even if it's not changing them, you just need to click the save. Settings > Permalinks and press Save Changes. This will more then likely fix the issue as I had to do it when I recently migrated a clients site.

Categories