WordPress blog URL change

The easiest and safest way to change WordPress blog URL.

Few days ago I've changed my WordPress blog hosting from CirtexHosting to HostMonster. I've used CirtexHosting for 2 years and HostMonster for more than a year, mainly for development purposes. So perhaps, within a few days, I'll post a review about their performance. In short, both of them provide very good web hosting services. However, this post is not about the review, it's about the temporary problem I've faced while shifting this blog hosting.

Problem Description: After you transfer your WordPress blog files from one hosting to another (or perhaps to your PC), initially you'll not be able to access your blog, until you point your previous domain to the new hosting DNS. But, before you change this DNS entry of your blog domain (in my case www.fayazmiraz.com), you may want to (and should) confirm that your new installation is working properly. For that, you'll need a temporary URL to work with your blog, for example: http://localhost/fayazmiraz/. However, according to WordPress settings, this will not work.

Solution: Since I've worked with WordPress before, I already knew a possible solution by making some changes in SQL. Still, I've Googled the problem to find the best solution, since changing SQL sometimes can be dangerous. So, if you have WordPress 2.2 or higher, then here is the best solution for you (Changing your WordPress Blog URL without using any SQL query, by hard-coding the URL in wp-config.php):

// Add the following lines to your wp-config.php:
define('WP_HOME', 'http://localhost/fayazmiraz');
define('WP_SITEURL', 'http://localhost/fayazmiraz');
// Note: replace 'http://localhost/fayazmiraz/' with your preferred temporary URL

Now, your WordPress Blog will be working with your new hard-coded Temporary or Permanent URL. In case of Temporary URL, after the testing is complete, delete those two lines and point the DNS entry of your domain to the new hosting DNS. For people familiar with CodeIgniter, this setting is very similar to what you might have done in your CI setting.

Important: Also you'll have to change your WordPress .htaccess file if you install your WordPress in a sub-directory of your web root.

This is what the .htaccess file looks like if your WordPress is installed in the website's root:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

This is what the .htaccess file looks like if your WordPress is installed in a sub directory named /sub/ (in relation to the website's root):

RewriteEngine On
RewriteBase /sub/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sub/index.php [L]

42 thoughts on “WordPress blog URL change”

  1. Does this override the settings which is at wp_options table as field name "siteurl".?

    So far i know that you have to change the values for wp_options otherwise all things simply won't work.

    Let me know if putting those two constants do every trick.

    1. Yes, it does. So the only problem is you'll not be able to change Blog URL from "Settings" in Admin panel, since above settings will override them.

      As far as every trick is concerned, it will work only for relative URLs. So if you have any site link hard coded inside your posts, obviously that wont work. In all other cases it will work fine, at least as far as I've tested.

      Oh and it works only for WordPress 2.2 and above.

  2. Pingback: Dave-Miller.com
    1. Russel vai, I actually found this recently, so I thought it'll help others too. Changing WordPress URL was a pain so far, since one needed to change the database entry here and there. So testing in localhost and then moving to the public domain was not as simple as drag and drop.

      Even better news is: after working on it for a while, I actually created an even better way. Hopefully, I'll be able to share it with you soon.

  3. Nice, i've moved hosting to hostgator because a lot of spammer that leave tons of spam comment that make Bandwidth Limit Exceeded just in few days.

    but how about import from localhost to public from WP dashboard, have you tried it.

    1. Import works fine, but import has two problems:
      1. If you have many plugins, custom theme and some custom changes in WordPress, then you'll have to do all those changes to your new WordPress instillation in the public domain. So evidently, in some cases you'll forget what change you actually did from the original default setting. So someway, the public version may become different than the local copy. But, transferring all the files using FTP doesn't have the same problem, if you follow my method.

      2. If you have many posts and comments, in other words a very big database, then import may create problems. Otherwise, for small database and default wordpress setting, import is fine.

  4. Making SQL queries is not that scary. There is a simple online tool to generate sql queries to Change a wordpress URL. There are always a bunch of settings besides the "siteURL" and "home" that you will have to update after the switch - by making these queries you can save yourself a lot of time and headache.

    1. Actually when you transfer your WordPress powered blog, from one domain to another, in that case changing database with SQL queries will not hurt, and it'll also keep your database clean.

      But for temporary URL change or for people with very few knowledge of SQL, this method will be more suitable. For example, in my case, I test my site locally first (in localhost), everytime I install a new plugin, change something in the theme etc.
      Then upload the new files to my site.

      If I used SQL to change site address, then I would have to run the queries every time I make a test. So that's why keeping the url in wp-config helps.

  5. I just had this problem what I did was simply update the to the URL and save settings (which of course takes your site offline). Move it then update your .htacess which if you have moved it from a root to a root of server won't be a problem but if inside a file inside your server root then will.

    1. If you move the site inside a "folder" of your server root, in that case you'll have to update your WordPress .htaccess to make it work correctly:

      .htaccess for root:
      RewriteEngine On

      RewriteBase /
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]

      .htaccess for "sub" folder inside root:
      RewriteEngine On

      RewriteBase /sub/
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /sub/index.php [L]

  6. I want to convert my website to WordPress. I have the plugin needed to keep .html on the pages. However, as you can see some pages " http://www.buildgreenenergy.info/Magnetic-Motor.html " have "M" capitalized in URL. I want to save all the new pages in WordPress as they were in the old website with the capital letters. I want to keep all the URLs as they are because of all the backlinks. Do you have any suggestions how to do this? I do not want to use a redirection plugin and change the URLs.

    1. Hi Jonny,

      Best way is to hire an expert and let him do the job for you. Since, there might be issues because of your server capabilities etc.

      You can hire them from freelance site like freelancer.com | elance.com etc.

      Still, if you want to do it yourself, you can follow the the instructions below:

      Assuming you have the right .html extension plugin (which should add an additional .html extension after each perma link WordPress generates):

      1. Go to wp-admin -> settings -> Permalinks

      2. Select "Custom Structure" and in the input box type the following:

      and save the setting

      3. As you create new post, after providing a post name, you'll see that permalink of that post will appear below the title. Now, set the permalink as you like (without .html of course)

      Upper cases will be converted to lower case, but don't worry, after submitting the post, you should be able to access the post with any "case" you like, since the links are case "insensitive".

      So, you'll still get all the back-links, and search engines will not demote your rating, since search engines also see the links in case insensitive manner.

      Hope, these instructions will help you.

      1. fayazmiraz,

        Interesting that you said "links are case insensitive". I believe anything after the / is case sensitive. Do you have an example of a website that is case insensitive?

        Just as there is a simple plugin for .html ( called .html on PAGES ), I am hoping to find the code or plugin for capital letters in url.


    2. Jonny,

      In Unix, file/folder names are "case sensitive", since most of the time a link (after the /) is also a file in the server, the link also becomes "case sensitive" in case of Unix servers.

      In windows however, file/folder names are "not" case sensitive. So any link that corresponds to a file to a windows server, is "case insensitive".

      Although, the important thing to keep in mind is that, WordPress posts do not correspond to any original file or folder in the server and WordPress engine itself considers the post URLs in a "case insensitive" manner.

      For example, my site is in a Linux Server, but it does not have any directory named "wordpress-blog-url-change", this is rather a generated link from wordpress. So although it is in a case sensitive Linux server, you'll be still be able to access this page in different cases; like:


      However, in my server there is a file named: "favicon.ico"
      You can access this icon file from this URL:
      But, any other case, for example: http://www.fayazmiraz.com/Favicon.ico
      will give you a 404 (not found) error.

      Although, if my site were in a windows server, even the files would be accessible from different cased links. For example, one of my client's site is in a Windows server, and files in that server can be access from different cased links.

      I believe this is enough explanation :), Thanks.

  7. Thank you for the explanation!

    I must be on a unix server (???) since all my websites are case sensitive after the / mark.

    Back to the problem which is http://www.buildgreenenergy.info/ is case sensitive after the / mark and I want to move it to WordPress. Since I cannot find a way to force WordPress to accept capital letters in the url, if I do a 301 redirect, what percentage of backlinks might I lose doing the 301?

    How long until search engines see the 301? (days,weeks or months)?

    Thanks for all the info! It has cleared up my understanding of why some url's are case sensitive and some are not.


    1. @Jonny

      First of all, you'll not need any 301 redirect after converting to WordPress. Even though WordPress forcefully converts all URLs to lower case, the same URLs still correspond to the upper cased version. So even in unix system, after converting to WordPress, your old Upper cased URLs will be accessible. For example, the following two URLs will be the same:


      Secondly, if you still do any 301 redirect, no back-link will fail to do 301. Although you'll have to keep the redirects forever. Since, search engines will correct the URLs, but some other sites (having back-link to your site) will never correct the link. They will always be using the 301 redirects.

  8. Hello, I really want to change my WordPress url but all this stuff is too tricky for me as I'm still young and have never learnt any of this before. If you could help me, please contact!

  9. Thanks for the post. I'm having a different problem and I can't find posts or tutorials on if this is possible.

    I have my current site at example.com it's joomla. I want to replace it with a WordPress site. So, i built a test site at wordpress.example.com hoping that I could just direct example.com to the folder on my server where all the files are for wordpress.example.com is this possible? Can I just do this with DNS?

    Most of the posts I'm finding are talking about changing hosts. I'm looking for a simpler solution if it exists.... I hope this isn't too off topic.


    1. I'm assuming your wordpress is in the folder wordpress in relation to web-root of example.com (i.e. the folder can be soft-linked as example.com/wordpress/).

      In that case do the following:
      1. Use the following .htaccess CODE in example.com web-root:
      # BEGIN WordPress
      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule (.*) /wordpress/$1 [L]
      # END WordPress

      2. Change the .htaccess of wordpress.example.com (i.e. the wordpress folder) for blocking wordpress.example.com and allowing only http://www.example.com:
      # BEGIN WordPress
      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{HTTP_HOST} !^www.example.com$
      RewriteRule ^(.*)$ "http://www.example.com/" [R=301,L]
      RewriteBase /
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]
      # END WordPress

      3. And finally, modify wp-config.php of wordpress.example.com so that it works with http://www.example.com. Add following two lines of codes in wp-config.php, preferably at the beginning of the file (just after the starting block comments):
      define('WP_HOME', 'http://www.example.com');
      define('WP_SITEURL', 'http://www.example.com');

      That should do the trick ๐Ÿ™‚
      Let me know, if you face any further problem.

      Also, checkout another post that deals with sub-domains

      1. Wow! This is very helpful! Maybe you should write a post on this so people can find it easily. I'm probably not the only who's tried to do this ๐Ÿ™‚


        One follow up question. Is there any reason why I shouldn't do it this way? Would it be better for me to just move my wordpress installation to the root on my server?

        Thank you for your help!

  10. @JP: well to be honest, there is no big reason for it.

    But, it's always better to serve your files conventionally. That way future updates and maintenance will become easier.

    For example, you may employ some other person to do maintenance for you, but at first glance he might be lost, since in most cases, he'll have no idea what's happening.

    So, if it's not too much trouble, then I suggest you do it in the conventional way and move wordpress to the server root.

    Although, if you maintain all the followup updates yourself, then I don't see much difference in either solution. So do what feels easy ๐Ÿ™‚

  11. So, I tried what you said and here's what happens:

    I type in example.com and it goes to the old joomla site. I type in wordpress.example.com and it goes to the old joomla site at example.com

    I just went to the DNS controls in 1and1 and changed the destination of example.com to the folder where my wordpress files are. I'm hoping that is the missing link. If not, please do let me know!


  12. Ok, everything seems to be working except for one thing that I can see. I uploaded some files before the switch and so they are in wordpress.example.com/wp-content/uploads/... when I click the link that I have on wp to the files, it just takes me to the wp homepage rather than starting a download.


    1. Yes, that is expected. Any hard-coded link with wordpress.example.com/.../ will not convert to http://www.example.com/.../

      You can do any one of the following (Option-3 is recommended):

      Option-1: if there is only a few links, update the links by manually editing the posts, so that links points to http://www.example.com/../ instead of wordpress.example.com

      Option-2: if manual link update is tadeous, then follow the link updating process in this POST (this uses SQL query, keep it as a last resort. Don't do it unless you have to): http://www.lancelhoff.com/wordpress-replace-url-or-text-in-all-posts/

      Option-3: Changing SQL can be dangerous. Especially, if you don't know exactly what you are doing. To be on the safe side, you an try modifying step-2 of my (previously commented suggestion):

      Change the .htaccess of wordpress.example.com (i.e. the wordpress folder) for blocking wordpress.example.com and allowing only http://www.example.com:
      # BEGIN WordPress

      RewriteEngine On
      RewriteCond %{HTTP_HOST} !^www.example.com$
      RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
      RewriteBase /
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]

      # END WordPress

      Notice the $1 in this line:
      RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

      In fact, this is the only change you'll have to do. Let me know how it goes.

      cheers ๐Ÿ™‚

  13. Hi Buddy, thanx a lot. I've been struggling with a sql queries to change url.
    didn't know it was that simple:)


  14. Pingback: Dave James Miller
  15. Will this work if my WordPress self hosted site needs a redesign and I want to have a maintenance page up while I work on it?

    1. Hello Rana,

      Follow these steps and you should be all set:

      1. Move (cut+paste) all files from /beta/ folder to your "web root" ("web root" is most likely one directory above "beta" folder)

      2. Change wp-configure.php to:

      3. Change .htaccess to:
      RewriteEngine On

      RewriteBase /

      RewriteCond %{REQUEST_FILENAME} !-f

      RewriteCond %{REQUEST_FILENAME} !-d

      RewriteRule . /index.php [L]

      That's it ๐Ÿ™‚

      Let me know how it turns out. I may not answer back immediately though, as I'm very busy at the moment.

      1. BTW, remember if you happen to have hard-coded links inside your theme file or post, then those links will have to be changed manually (for theme files) or using SQL query (for posts).

        Of course, in that case, you can also use a rewrite rule in the .htaccess file to redirect them to your base url, (as a quick shortcut) ๐Ÿ™‚

Leave a Reply

Your email address will not be published. Required fields are marked *