Changing The URL Of Your WordPress Site

WordPress web site owners often come to realize that they want to change the URL of their web site, whether it is because they want the site to be accessible from the root folder (without using a redirect) or because they want to change the domain name of the web site.

If you’d like to do this, first ask yourself if you feel comfortable editing the code in your theme files, and if you feel comfortable using FTP to upload the edits to your web server. Remember to use a plain-text editor to make all of your edits, not a word processing program like MS Word. If you can do those things without hesitation, you’ve made it over the first hurdle.

The next thing you have to do is decide whether you are going to make the domain name point to your WordPress folder or if you are going to copy the site files from your WordPress folder to the folder that the domain name points to.

  • If the domain name is changing, you can often point the new domain name to the WordPress folder when you add it in your hosting control panel, and not have to copy or move any files at all.
  • If the domain name is not changing but the path to the site is (e.g. moving WordPress to the root folder), and/or you don’t know how to point your domain to a specific folder at the hosting level, you can simply copy all of your WordPress site files via FTP to the folder that the domain name points to.

Two things to do before you upload your site files

Check the .htaccess file in the WordPress folder: WordPress usually writes entries to a .htaccess file in the main WordPress folder. If you are moving the site from a sub-folder to the root or vice-versa, you will have to edit this file. If your site is in a sub-folder called /blog, the .htaccess file in your WordPress folder will contain these lines:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress

If your site is going to be in the root folder, the references to the sub-folder need to be removed, making it look like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Add two lines of code to the functions.php file of the Default theme: As shown in the WordPress Codex article Changing The Site URL, you can add these two lines of code to the top of your functions.php file to tell the database the new site URL:

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

Replace example.com with your actual domain name and any sub-folder name that points to your site. The only reason I suggest doing this to the functions.php of the Default theme is so that you don’t have to mess with your active theme’s files. If you prefer to edit the functions.php of your active theme, that will work too. It is advisable to make backups of your functions.php file and your WordPress database at this time.

If you have chosen to edit the functions.php of the Default theme and that is not your active theme, go to your site’s admin at the old URL and activate the Default theme. If you edited the functions.php of your active theme, you can skip this step.

Now that you’ve done your edits, you can upload all of the necessary files to the proper folder. If the folder is not changing, you only need to upload the new functions.php, and possibly the new .htaccess file. If you are changing the folder, upload the entire site to the new folder.

Now simply go to your site at the new URL. It should work. Assuming it works fine, you can upload the backup version of the functions.php (i.e. one that has not been edited). It is important to remove those extra lines of code. Your site is now ready to go.

Additional considerations:

  • If you are using a plugin that references a file in your folder structure such as the Google XML Sitemap Generator or a database backup utility, you may need to change the path in the plugin’s settings to the new path.
  • You may also need to change the path to your uploads folder in Settings > Miscellaneous
  • You may want to use the Broken Link Checker plugin to make sure that you don’t have any broken internal links or redirects in your site caused by the URL change.
  • If you feel brave and have a lot of internal links that need to be changed, you can use the Search and Replace plugin to change them all simultaneously.
  • If you have moved your WordPress site to a new folder on the server, remember to delete the old files.
  • If you have changed your domain name remember to put in a .htaccess 301 redirect from the old location to the new one.
  • It is advisable to put a robots.txt file in your root folder so that search engines will crawl and re-index the site. Google may reject your sitemap if you don’t have a robots.txt file giving them access to crawl the site.

If this seems too difficult for you, you may be interested in my article on Accessing Your WordPress Site From The Root Folder, which explains how a simple .htaccess redirect file can point requests from your root URL to your WordPress folder.

Have fun!

This article copyright © John Nasta 2010 – All Rights Reserved
Be Sociable, Share!

You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

16 Comments »

 
  • Merk says:

    thank you for a great post. it seem very simple, I just wonder what will be the steps if one wish to test the new site before changing the DNS..

  • Jortiz says:

    First thing to consider before making any changes to Word Press files is to make a back up.

  • Ishan says:

    After changing the site url uploading not working!
    Error prompt is ““filename.gif” has failed to upload due to an error
    The uploaded file could not be moved to /home/kkcem/public_html/wp-content/uploads/2012/11.”

  • Debbie Gray says:

    If I point a domain to a WordPress installation that I’ve been working on, do I need to change the Home URL setting in the WordPress dashboard? It’s the only domain I want associated with the site.

    • John Nasta says:

      Ultimately, the best thing to do is change the URLs in Settings > General to the URL that you want, then point the domain name to the folder that the WordPress files are in.

  • Emily says:

    Hi there,

    thanks so much for this, I am knew to wordpress and just learning all thr ropes & it really helped me on a site I am doing.

    you mentioned about adding a robots.txt file to the root folder. do you have anymore information about robots.txt & what it should contain?

    Cheers

  • John,

    About a year ago I got my blog site put onto a subdomain blog.myfoundationfitness.com and I’m wanting to move it to a root domain patrickhitches.com … I’ve read so many articles on this and I think it may just be outside my ability. Any recommendations of people that do this on the side who would take all things into consideration to optimize the switch?

    Thanks John,

    Patrick

  • Letra says:

    Hey, quick question…so if i move from website.com/blog to website.com the links will loose popularity on google ?

    • John Nasta says:

      Your site will have to be reindexed because all of your links will change. If you have a strong Google rating, you may want to consider a .htaccess redirect so that your home page resolves at website.com instead of actually changing the URLs to all of your pages.

  • Mark says:

    I’d love some advice re setting up a blog on a sub-directory before a domain name is pointed to my DNS… I hope this makes sense.

    So http://www.mydomain.com is an HTML website and is being hosted by a 3rd party.

    I want to prebuild a blog on my hosting to replace http://www.mydomain.com
    I will create the blog first on http://www.blog.mydomain.com and when I’m finished will point http://www.mydomain.com to my DNS.
    Then I’ll clone http://www.blog.mydomain.com and move it to the root directory.

    This is where I’m confused.

    Will I be able to preview the blog before http://www.mydomain.com is pointed to my server?

    If I create a page on the blog, is the URL going to be http://www.blog.mydomain.com/page-name or can it be http://www.mydomain.com/page-name
    If it’s the former, then when I clone the site, I’m thinking the site structure will be “buggered up” and in need of repair.

    Do you have any advice? Suggestions?

    Thanks

    • John Nasta says:

      Create it in a sub-folder like http://www.mydomain.com/blog and you can move it to the root directory after it’s finished. Remember to block search engines and hold off on the SEO plugins until the site is finished. You can also use a plugin like Members Only so that nobody can see your dev site at all without a password.

 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*