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

25 Responses to “Moving Wordpress”

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

  2. darkbluesun says:

    I’m glad to share, Glenda. :)

  3. forex robot says:

    nice post. thanks.

  4. 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.

  5. 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

  6. darkbluesun says:

    Thanks for the stumble! :)

  7. Paul Baker says:

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

  8. There is so much information here! I’m trying to remember all of it so I can put it to work….

    Another great post!…

  9. Substantially, the article is really the greatest on this deserving topic. I fit in with your conclusions and will thirstily look forward to your upcoming updates. Just saying thanks will not just be sufficient, for the wonderful lucidity in your writing. I will directly grab your rss feed to stay abreast of any updates. Good work and much success in your business dealings!

  10. 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.

  11. 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.

  12. darkbluesun says:

    I am very glad to hear this. :)

  13. darkbluesun says:

    I am very glad to hear this. :)

  14. I enjoyed the article and thanks because of posting such valuable appellation hurt of all of us to plunk down to to, I occur it both of use and communicative and I map to name it as commonly as I can.

    ray ban 3025

  15. This is very different from the type of arbitrage discussed in the previous part and in many ways can be more profitable…

  16. This is a incredible blog and I covenant mammoth on reading it every morning recriminate you
    honestly sharing it!

    louis vuitton handbags

  17. Another great post!

  18. 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

  19. 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.

  20. darkbluesun says:

    Thanks for the comment. :)

  21. free trial says:

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

  22. 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.

Leave a Reply