Moving WordPress

Saturday, January 2nd, 2010

Move WordPress from a subdirectory to website root

This example should work for any WordPress deployment, this article describes how to move WordPress on IIS 7 using ASP.Net

Benefits

  • Move WordPress
  • Preserve old links and permalinks
  • Preserve old images and uploads in posts and pages
  • Notify crawls of change with HTTP Response 301 Moved Permanently

This configuration will allow you to move WordPress to a different directory within your site and maintain you old links, permalinks, images, and uploads. All of the content will move with WordPress, this will just setup redirects to the new location. Each time an old link is used a HTTP Response 301 will be issued, this will help update search engines and backlinks. Custom HTTP Response 404 handling will be used to issue the HTTP Response 301.

Steps

  • Setup HTTP Response 301 Moved Permanently using ASP.Net (default.aspx)
  • Modify HTTP Response 404 Not Found handling using IIS 7 (web.config)
  • Modify rewrite rule to exclude old path using IIS 7 (web.config)
  • Update WordPress settings in database using MySQL
  • Update WordPress posts in database using MySQL

HTTP Response 301 Moved Permanently using ASP.Net
example default.aspx

<%@Page Language=”VB” %>
<%@Import Namespace=”System.Uri” %>
<%@Import Namespace=”System.Web” %>

<script runat=”server”>

Sub Page_Load(sender As Object, e As System.EventArgs)

Dim sUrl As System.String = HttpContext.Current.Request.RawUrl

Dim bChange As System.Boolean
bChange = False

If sUrl.IndexOf(“?404;”) > 0 Then
sUrl = sUrl.SubString(sUrl.IndexOf(“?404;”) + 5)
sUrl = sUrl.SubString(sUrl.IndexOf(“//”) + 2)
sUrl = sUrl.SubString(sUrl.IndexOf(“/”) + 1)
Else
sUrl = “”
End If

If sUrl.IndexOf(“blog/”) = 0 Then
sUrl = sUrl.SubString(5)
End If

Response.Status = “301 Moved Permanently”
Response.AddHeader(“Location”, “http://www.domain.com/” & sUrl)

End Sub

</script>

Web Server/IIS updates
example web.config


<?xml version="1.0" encoding="UTF-8"?/>
<configuration>
<system.webServer>
<httpErrors>
...
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/default.aspx" responseMode="ExecuteURL" />
...
</httpErrors>
<rewrite>
<rules>
<rule name="WordPress" stopProcessing="true">
<match url="/*" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="blog/*" matchType="Pattern" negate="true" />
</conditions>
<action type="Rewrite" url="/index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

WordPress updates
example MySQL synax


/* Update WordPress siteurl attribute */
update database_name.wp_options set option_value='http://www.domain.com' where option_name='siteurl';

/* Update WordPress home attribute */
update database_name.wp_options set option_value=’http://www.domain.com’ where option_name=’home’;

/* Update WordPress upload_path atribute, this is a local path */
update database_name.wp_options set option_value=’C:\\Inetpub\\website\\wp-content\\uploads’ where option_name=’upload_path’;

Pass it on!
  • Digg
  • email
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Netvibes
  • RSS
  • StumbleUpon
  • Yahoo! Buzz
  • Live
  • MySpace
  • Technorati
  • Twitter
  • del.icio.us
  • Reddit

If you have any information to add to this site, leave a comment and let me know! Your comments add value to this site, you will get the credit for them. And if they are really good then I will add value to your site by creating a backlink to your site or blog post as long as it is relevant to the material in this site.

18 Responses to “Moving WordPress”

  1. Glenda Beamish says:

    Hello there – just a short note to say kudos for this entry. Very great.

  2. Currently traveling between Miami and Florida, reading this on my Iphone. Will read it in full when I get back, and I will also post a backlink on my website. Thanks.

  3. Nice One says:

    I like your style, the fact that your site is a little bit different makes it so interesting, I get fed up of seeing same-old-same-old all of the time. I’ve just stumbled this page for you :-D

  4. darkbluesun says:

    Thanks for the stumble! :)

  5. Paul Baker says:

    Love the blog you have here! I find that information really interesting. :)

  6. ray ban store says:

    I enjoyed the article and thanks recompense posting such valuable communication as opposed to of all of us to skim, I be the start up it both sturdy and communicative and I method to catch on it as again as I can.

  7. I am impressed with all this useful information. Was WAY more than I expected. I just cannot keep up with your posts. So much information to read about.

  8. Edward Hernandez says:

    Another great post!

  9. UGG Boots says:

    I in purport enjoyed reading your blog and draw attention to adjacent to it both illuminating and interesting. I purposefulness be fateful to bookmark it and descend upon it as oft as I can.

    Thanks

    Bernice Franklin

  10. I have been a reader for a long while, but am a first time commenter. I just wanted to say that this has been / is my favorite update of yours! Keep up the good work and I’ll keep on checking back.

  11. darkbluesun says:

    Thanks for the comments. :)

  12. free call international says:

    You saved my day again.

  13. free trial says:

    After reading you site, Your site is very useful for me .I bookmarked your site!

  14. C Brakewell says:

    Food for thought, (at least the bits I could make out easily). I am afflicted with color blindness (deuteranopia in my case). I use Chrome browser (no idea if that makes a difference), and much of this webpage is a bit of a strain on my eyes. I don’t wish to whinge, and I know it is my problem really, nevertheless it would be great if you would consider color blind surfers whilst carrying out the next webpage redesign.

  15. Aileen Wisk says:

    Did you create your own blog or did a program do it? Could you please respond? 88

  16. darkbluesun says:

    I created my own with WordPress.

  17. I really liked your blog! It helped me alot…

Leave a Reply