banner



How To Change My Wordpress Blog Url To Subdomain

Installing WordPress in a subdomain is a great way to create a staging environment for development. The subdomain (for example http://dev.askwpgirl.com) is a self-contained space to do development without interfering with the live site. When the development phase is complete, the question becomes "How do you move WordPress from the subdomain to the root?"

Note: If you installed WordPress in a subdirectory (e.g. http://mysite.com/subdirectory) and not in a subdomain (http://subdomain.mysite.com), then please see How to move WordPress from a subdirectory to the root.

You can "move" WordPress from the subdomain to the root domain using one of the following approaches:

  • Back the site up using a backup or migration plugin (such as BackupBuddy, Duplicator, or All-in-One WP Migration). While leaving the subdomain of the site intact, you can restore the backup of the subdomain to the root directory. This is a nice option as it allows you to keep the WordPress install in the subdomain as a perpetual staging environment for testing WordPress updates or trying out new plugins or code.
  • If you do not want to maintain two WordPress installs on your hosting account (which is twice the work as maintaining one site and necessary to prevent hacking), you can do one of the following:
    • move the WordPress install to the root directory
    • keep the WordPress install in the subdomain folder, but rewrite the URLs to display them from the root
    • use one of the plugins mentioned above to "migrate" the dev site to the root directory then delete the subdomain.

Below are instructions for how to move or show the site from the root directory without using a migration plugin.

Before moving WordPress from the subdomain to the public_html (aka www or "root") folder

Note: When I say "root" I mean the domain root NOT the hosting root folder. The domain root folder is typically called html, www, or public_html on most web hosts. Some WordPress installs are pretty gnarly with folders inside of folders inside of folders, and finding the folder that the host considers to be the primary domain root folder can take some digging.

1 – Be sure you have access to your web hosting control panel and File Manager within the control panel as well as access to phpMyAdmin should you need to revert the changes you make to the WordPress General Settings below.

2 – Make a back up of your database using UpdraftPlus or BackWPUp plugin. Download this file and keep it safe.

3 – Remove any old site files from the public_html directory — perhaps copy them to a folder called _backup – this includes an index.html file which will totally make this process not work. You MUST remove all those old site files and folders or move them into another directory, so they don't interfere with WordPress. Having an index.html and index.php in the same folder causes confusion, and likely, the index.html will be used instead of WordPress' index.php file. Do not move server related folders in the public_html directory such as cgi-bin. It's okay for those to stay in place.

4 – Make sure you don't have any other folders in the root directory that have the same name as any pages on your WordPress site, for example "blog" unless of course this is the name of your subdirectory install of WordPress in which case you cannot have a page of the same name because the browser will get confused and look for that page in that folder, then things are really confused.

5 – If you are using a caching plugin, delete all cached pages and de-activate caching.

Option 1: Move WordPress from subdomain folder to public_html directory

This is the most straight forward process to get WordPress out of the subdomain and into the root directory.

1 – Go to Settings > General and change the URL for both the WordPress Address and Site Address to use the main domain name. Be sure to remove the trailing / . Click Save Changes.

general-settings

2 – Using FTP or the web host's File Manager, you will need to MOVE all of the WordPress files from the subdomain's folder up one level to the public_html aka domain root folder.

To do this with FTP, in the remote server area of the FTP application window, toggle open the subdirectory containing the WordPress installation you wish to move. Select all the files in this directory and drag them out of this directory and into the public_html folder or whatever directory this directory is within.

If you are using the File Manager on the web host's control panel:

  • Double click the subdirectory containing the WordPress files to expand it open.
  • Click Select All to select all the files and folders.
  • Click the Move File icon.
  • In the Move dialog box, remove the subdirectory from the path field, so the path you are moving to is /public_html
  • Click Move Files.

(Note: Some hosts might have a different name for this folder or you may have installed WordPress in a subdirectory inside another directory. Just remove the current subdirectory from the path along with the forward slash /, but don't remove anything more than that.)

The files should now be moved to the public_html.

file-manager

3 – Login to WordPress in the root directory which should be your domain name plus /wp-admin, e.g. http://mywebsite.com/wp-admin.

4 – Go to Settings > Permalinks and click Save Changes. This will rewrite the .htaccess file that controls the  "pretty" URLs on the site. This likely isn't going to be an issue when you are using a subdomain install, as the .htaccess contents should be correct.

5 – Install the Velvet Blues Update URLs plugin.

Under Tools > Update URLs, type the subdomain website address in the Old URL field and the main website address in the New URL field.

Be sure to not end the URLs with a forward slash /. If you do end it with a forward slash, end it with a forward slash for both URLs not just one. Consistency is important here.

Be sure to NOT not update all GUIDs. This will result in many theme settings to reset and posts to republish to the RSS feed.

6 – Click the Update URLs button. This should catch most of the URLs on the site. However, if it seems to miss several, you can try repeating this process without the http:// part of the URL, and see if it catches more.

Moving WordPress Subdomain to Root using Velvet Blues Update URLs plugin

7 – Check for other URLs not caught with the Velvet Blues plugin including:

  • Appearance > Menus — check for any custom URLs to the old site URL in any custom menu items, such as the home page link.
  • Appearance > Theme Options or your theme's Theme Options page — check the URLs for any uploaded files such as the logo or favicon and remove the subdirectory from the URLs as needed.
  • Sliders — If you use Revolution Slider or other slider plugin may not update the URLs to the slider images with the Velvet Blues plugin. Edit the slider and remove the subdirectory from any image URLs.
  • Shortcodes and custom layouts — Some shortcodes for button links or custom theme layouts may contain URLs to the subdirectory which you may need to manually change. If you can find a pattern to these, you can try to run the Velvet Blues plugin again using the URL pattern you find.

8 – Test the site and be sure everything is appearing as expected. If anything is amiss, be sure to clear your browser cache completely or test in a browser you don't usually use.

9 – Reset the caching and update the .htaccess file per the caching plugin instructions as needed.

Please comment below if you have any issues, as I can write more instructions for troubleshooting as needed. The main issue with this technique is that it's possible for people to move the WordPress files BEFORE making the URL edits in the General Settings, and that will make the site inaccessible. However, this is quickly remedied by going into phpMyAdmin and accessing the wp_options table and changing the site and home URL as needed.

Option 2: Keep WordPress in the subdomain's folder but show the URLs from the root

This option is slightly less intimidating because it doesn't involve moving all the WordPress files. You only need to copy one file and move that to the public_html directory. This process will not allow you to access the WordPress installation via the subdomain any longer. It simply allows you to keep WordPress in the subdirectory (aka subfolder) on the hosting account created for the subdomain but essentially makes the subdomain not usable unless you recreate the subdomain and have it point to a different folder.

The only issue with the process below is if you created a not-so-user-friendly subfolder name for the installation, such as "dev" or "test" or "staging." This would not be a professional folder name to use on a live site. Even though this process will allow you to show the URLs from the root of the domain, your uploaded images, PDFs, and other media files will reference the subdirectory (subfolder) name.

Changing the WordPress Subdomain/Subfolder Name

If you want to throw complete caution to the wind, you could go ahead and rename the subfolder, and I will tell you below EXACTLY at which point in the process to do so, so you don't lock yourself out of the site. But, have no fear! If you do mess up the folder name or the URLs, you can always fix this in the database using phpMyAdmin. In fact, trying this process on non-critical websites can build confidence in future migrations. Breaking things is always a great way to learn! Just maybe not on a client's site.

Keeping WordPress in the subdomain folder but showing URLs from the root

1 – In your web hosting control panel File Manager or FTP application, please take note of the folder name of the subdomain installation. This is typically the same name as the subdomain, e.g. dev, staging, blog, test, etc., but sometimes it is different, so make sure you know what it is before proceeding.

2 – Go to Settings > General. What you will see is something like this:

subdomain-general-settings

You need to change the URLs to this where the WordPress Address is the main domain URL with a forward slash followed by the folder name you made note of in step 1 above, and the Site Address is the main domain URL.

subdomain-folder-name

Now is the opportunity to CHANGE the folder name but don't do it in the File Manager or FTP yet. If you want to use a different folder name, enter that in the WordPress Address field, e.g. http://mydomain.com/newfoldername, then we will rename the actual folder in step 4 below.

3 – Click Save Changes. You will be immediately kicked out of the site.

4 – If you changed the folder name in the WordPress Address field, go ahead now and change the folder name in your control panel's File Manager or FTP application.

5 – While you are in the File Manager of FTP application, download the index.php file in the subdomain's folder.

6 – In a text or HTML editor, open the index.php file that you just downloaded and change the location of thewp-blog-header.php to tell WordPress where it can find the WordPress application files in the subdirectory:

Example: if your WordPress installation folder is 'subdomain', you would change:

require( dirname( __FILE__ ) . '/wp-blog-header.php' );

to

require( dirname( __FILE__ ) . '/subdomain/wp-blog-header.php' );

Important: Be sure you type this correctly! A missing / or too many slashes or missing period or apostrophe can make this not work. Believe me, I've seen people be totally freaked out things didn't work and it was because they typed this line wrong.

Do NOT edit this file in Word or any text editor that uses Rich Text as it will turn the straight quotes curly and will break your site. If you don't have a code editor application, then upload the file to your hosting account (see Step 7 below) and then edit it using the Editor feature in the File Manager instead.

7 – Upload this edited index.php file to the public_html folder on the hosting account. The file structure will look something like this:

cpanel-file-manager

8 – Login to WordPress in the root directory which should be your domain name plus /wp-admin, e.g. http://mywebsite.com/wp-admin.

9 – Go to Settings > Permalinks and click Save Changes. This will rewrite the .htaccess file that controls the  "pretty" URLs on the site. This likely isn't going to be an issue when you are using a subdomain install, as the .htaccess contents should be correct.

10 – Install the Velvet Blues Update URLs plugin.

Under Tools > Update URLs, update your URLs as follows:

velvet-blues-change-subdomain-subdirectory

In the New Site Address field enter the URL to the correct folder name for the WordPress install that is in your Settings > General for the WordPress URL.

Be sure to not end the URLs with a forward slash /. If you do end it with a forward slash, end it with a forward slash for both URLs not just one. Consistency is important here.

Be sure to NOT not update all GUIDs. This will result in many theme settings to reset and posts to republish to the RSS feed.

11 – Click the Update URLs button. This should catch most of the URLs on the site. However, if it seems to miss several, you can try repeating this process without the http:// part of the URL, and see if it catches more.

12 – Check for other URLs not caught with the Velvet Blues plugin including:

  • Appearance > Menus — check for any custom URLs to the old site URL in any custom menu items, such as the home page link.
  • Appearance > Theme Options or your theme's Theme Options page — check the URLs for any uploaded files such as the logo or favicon.
  • Sliders — If you use Revolution Slider or other slider plugin may not update the URLs to the slider images with the Velvet Blues plugin.
  • Shortcodes and custom layouts — Some shortcodes for button links or custom theme layouts may contain URLs to the subdirectory which you may need to manually change. If you can find a pattern to these, you can try to run the Velvet Blues plugin again using the URL pattern you find.
  • Any manual links to internal pages will need to be edited to point to the domain without the subfolder in the URL.

13 – Test the site and be sure everything is appearing as expected. If anything is amiss, be sure to clear your browser cache completely or test in a browser you don't usually use.

14 – Reset the caching and update the .htaccess file per the caching plugin instructions as needed.

This process is obviously more steps, and you need to be careful with each step to make sure you type the correct URL and folder names. Otherwise, it's actually pretty simple. I think the most difficult part here is that you essentially going from a subdomain install to a subdirectory install then taking it one step further to show the URLs from the root domain and in this whole process you may have gone wild and decided to change the folder name while you were at it!

Fixing WordPress URLs in phpMyAdmin

For both of these processes, the main mistake that might be made is to the URL fields. A simple typo can really cause problems. To fix this, log in to your web hosting control panel and go to phpMyAdmin. If you are prompted for a username or password for the database, you can find both of these in the wp-config.php file in your WordPress install. (Tip: In the File Manager, you can view the wp-config.php file and copy the username and password to a text file on your computer for easy reference.)

1 – Once in phpMyAdmin, click on the wp_options table.

2 – Click the Browse tab at the top of the phpMyAdmin to see the contents of the wp_options table.

3 – Look for the two options names: siteurl and home.

phpmyadmin-wordpress-wp-options-siteurl

4 – Check to make sure these are correct. If you did the process outlined in Option 1 above, both of these should be simply the website URL (e.g. http://mysite.com). If you did the process outlined in Option 2 above, the siteurl should contain the subfolder name. Check the File Manager or FTP application to make sure you have it correctly entered. The home URL should be the main URL for the site.

5 – If you need to edit these, click the pencil icon, make the changes, then click the Go button to save the changes.

Let me know if you get stuck! Write in the comments or contact me directly. I can often provide quick advice. If things are not easy to address via email, I am available for hire. It typically takes me 5-15 minutes to login and figure things out.

I would love if you could Tweet about this if it helped you!

How To Change My Wordpress Blog Url To Subdomain

Source: https://askwpgirl.com/move-wordpress-subdomain-root/

Posted by: mooretaks1965.blogspot.com

0 Response to "How To Change My Wordpress Blog Url To Subdomain"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel