I originally installed wordpress in a subdirectory called /blog. Today I decided to change the URL of my site to remove the /blog element from the URL e.g. from www.mywebsite.com/blog to www.mywebsite.com. Here is what I did:

  1. went to settings > general and changed the site address:

WordPress Address (URL): www.mywebsite.com/blog

Site Address (URL): www.mywebsite.com

  1. deleted my original homepage (index.html)

  2. downloaded the index.php file from the /blog directory, and uploaded a copy into the root directory

  3. opened the index.php file from the root directory and changed the following line of code:

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

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

This worked in that I now landed directly on my wordpress blog when I typed in www.mywebsite.com, but all my internal links resulted in 404 errors. So I changed my permalinks to plain (e.g. wwww.mywebsite.com/?p=123), which fixed the broken links. However, I prefer to use the post name structure (e.g. wwww.mywebsite.com/name-of-post) so tried to fix this by doing the following:

  1. created a file called .htaccess in the root directory, and typed in the following code:

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

This went horribly wrong, resulting in 500 errors that locked my out of the WP dashboard for some time. I can't remember exactly how I fixed this, but the only other change I made was as follows:

  1. edited web.config file in /blog directory:

    <?xml version="1.0" encoding="UTF-8"?>
    <rule name="WordPress Rule" stopProcessing="true">
    <match url=".*" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <action type="Rewrite" url="index.php" />

This still didn't allow post name permalinks, so I set permalinks back to plain. However, I now have a weird situation where about half of my internal links work okay, and the other half result in 404's. I don't really understand how this is possible, as I would have thought it would be all or nothing!

Can anyone please help?

UPDATE - NOW RESOLVED (YAY!): After struggling to fix this, I contacted the support helpline for the company that provides my web hosting. They said that the fact I was on a windows server was problematic, as it is not really compatible with WordPress. So this is what I / they did:

  1. phoned my web host providers and changed to a LINUX server
  2. downloaded the free FTP application FileZilla, and imported all of my wordpress files onto my computer. I then transferred them via FTP to the new LINUX server, into the root directory (public_html).
  3. exported my WordPress database from the old windows server and saved onto my computer. I then created a new database in the new LINUX server and imported the WordPress database (I have to admit something went wrong here, so the support guys ended up doing this for me)
  4. my web host provider then pushed the LINUX site live (again, something went wrong here so another phone call was involved in getting them to fix the problem).
  5. Used the plug-in 'Velvet Blues Update URLs' to update all instances of www.mywebsite.com/blog to www.mywebsite.com in posts, links and attachments (i.e. images were not displayed until I did this)
  6. turned on permalinks and checked it worked

This was a bit of a palava, but got there in the end. I'm sure there are much easier ways to achieve this, but I'm posting this solution just so non-technical people like myself realise they can call the helpline for their web hosting platform rather than trying to struggle through.

2 Answers 2


Please use this query in your Database using PhpMyAdmin

UPDATE wp_options SET option_value = REPLACE(option_value, 'oldsite.com', 'newsite.com'); UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'oldsite.com', 'newsite.com'); UPDATE wp_posts SET post_content = REPLACE(post_content, 'oldsite.com', 'newsite.com'); UPDATE wp_posts SET post_excerpt = REPLACE(post_excerpt, 'oldsite.com', 'newsite.com'); UPDATE wp_posts SET guid = REPLACE(guid, 'oldsite.com', 'newsite.com');

This will change all your URL's to new ones.


You need to update all the links in your database as well

You need to use something like Search-Replace-DB to accomplish this, do not modify the database manually

when you use the software, you would try to search for strings like

http://www.example.com/blog/ and replace it with http://www.example.com/

you would also try to find your absolute directory path and update that as well

/var/www/mysite/html/blog/ to /var/www/mysite/html/

you shouldn't have to mess with your template files, or any other PHP file for that matter. But that would be a case specific scenario.


Be careful and always have a good backup of your DB (and your files) when using Search-Replace-DB messing something in your replace string and you could badly mess up your database... if that happens, just restore your DB backup and try again.

Be sure to delete the folder containing Search-Replace-DB when you're done for security reasons

  • Thanks for the help. I didn't know about the existence of a SQL database. I've been looking at the wp_posts table, where I can see a GUID which equates to the plain permalink. I used a plug-in to find all instances of www.mywebsite.com/blog/ in database posts, links and attachments and replace with www.mywebsite.com/. However, this broke my site completely, until reversed. So which tables / fields in particular should I be changing? Also, if my wp content such as images are still held in the subfolder www.mywebsite.com/blog/ wouldn't changing the links mean that the content couldn't be found?
    – Rwth
    Mar 21, 2017 at 23:06
  • If you use the Search-Replace-DB script, you will fix all instances in your database. Trying to manually edit the database will break things because the data is serialized in the DB and modifying even a letter of it will break the serialization and mess up your data. As for your assets... they should be moved too (out of the /blog structure) if you don't then it'll be hard, next to impossible, to use Search-Replace-DB since the script will change all instances of the .../blog it finds. And like you said, it will likely break those links
    – bynicolas
    Mar 22, 2017 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.