Moving WordPress
Saturday, January 2nd, 2010Move 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 = FalseIf 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 IfIf sUrl.IndexOf(“blog/”) = 0 Then
sUrl = sUrl.SubString(5)
End IfResponse.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’;









Hello there – just a short note to say kudos for this entry. Very great.
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.
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
Thanks for the stumble!
Love the blog you have here! I find that information really interesting.
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.
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.
Another great post!
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
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.
Nice post
Thanks for the comments.
You saved my day again.
After reading you site, Your site is very useful for me .I bookmarked your site!
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.
Did you create your own blog or did a program do it? Could you please respond? 88
I created my own with WordPress.
I really liked your blog! It helped me alot…