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:
- went to settings > general and changed the site address:
WordPress Address (URL): www.mywebsite.com/blog
Site Address (URL): www.mywebsite.com
deleted my original homepage (index.html)
downloaded the index.php file from the /blog directory, and uploaded a copy into the root directory
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:
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] </IfModule> # 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:
edited web.config file in /blog directory:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="WordPress Rule" stopProcessing="true"> <match url=".*" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="index.php" /> </rule> </rules> </rewrite> </system.webServer> </configuration>"
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:
- phoned my web host providers and changed to a LINUX server
- 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).
- 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)
- 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).
- 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)
- 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.