The challenge
I received an email from one of our clients, http://www.babylovesorganic.co.uk asking us the following question: "How difficult is it to move our blog site to within the main web site, off a blog directory"
The blog is on blog.babylovesorganic.co.uk, and is written using Wordpress (so - php), the main site http://www.babylovesorganic.co.uk is an e-commerce site built using our e-commerce engine and is written in .net (so not php). What we need to do is get php working within an asp.net style site. A bit of thought and we had our list of whats needed.
The steps we needed to perform to do this are as follows
- Get php support working from within IIS.
- Create the /blog/ folder on the new site URL and configure it.
- Copy the wordpress site over to the new location
- Configure wordpress in the new location.
- Redirect all old site links to the new location (using 301 redirects in IIS).
Seems easy, if you say it quickly it doesn't sound a lot either
We got it working very quickly, and where suprised how easit it was... Here's how we did it for our client:
Get php support working from within IIS.
This is really, suprisingly easy. A lot of asp.net developers think that this can't be done, some think its really difficult - I guess that this is because they're used to IIS just supporting what they do out of the box - with little / no configuration changes.
Whats needed is some plugging into IIS additional configuration for php files and an object to handle the php requests. Thankfully there's a really simple solution to this already in the asp community, freely available from iis.net. Simply go to http://www.iis.net/community/default.aspx?tabid=34&g=6&i=2007 and download PHP Manager from there and install it on your IIS server.
There's some really easy to follow instructions on there too (at the codeplex site: http://phpmanager.codeplex.com/wikipage?title=Managing%20PHP%20installations%20with%20PHP%20Manager%20user%20interface) - They're what we followed, but if you need some help - let us know.
Create the /blog/ folder on the new site URL and configure it.
Given its IIS, creating the blog folder is as simple as creating a blog folder in Windows Explorer. Then go back to IIS and refresh the site. You'll see the blog folder there.
We now need to configure this, we need to tell IIS that this folder works differently to the rest of the site. In IIS, right click the folder and select "Convert to application"
You'll get a screen like the one below (Obviously your sites path will be in the Physical path):

Switch the Application Pool
Essential work is needed on this screen, you need to amend the application pool. It'll be set by default to use the same one as the rest of the site - which is geared up for ASP.NET / MVC.NET style code. So click the "Select..." button to change. When you installed the PHP Manager, it will have created a "PHP Pool" too. For now, use this one.
This is what we've done, although we've actually created another app pool similar to PHP Pool and given it a more explicit site reference as a name.
Checking its right
If you want to check its right, click the Blog application in IIS and select the PHP Manager icon in the IIS section of the options shown. This shows the current PHP status for the Blog application. If you've followed the steps correctly then it will be all ok. If not then use the diagnostics and PHP manager documentation... or get in touch with us.
Copy the wordpress site over to the new location
Nothing complicated here, simply copy the whole of the wordpress installation from its original location to the new one (using the /blog/ folder as the destination). We had the wordpress site on the same server so it really was a simple copy... and yes, we copied it so that we had the original there just in case we got something wrong!
Configure wordpress in the new location
Two things to bear in mind here.. of you've moved wordpress to a new server - make sure that the new server has access to your mySQL implementation.. its amazing how many developers forget about permissions and start to flap their arms and go crazy when things "just don't work on new servers". On new installations, 80% of problems are permissions related! Just make sure that it has access and that you've got youe php configuration correct.
Second thing to set, is the url configuration within wordpress itself. Go to the new blog url wordpress admin (wp-admin) and select the general settings option. You'll need to adjust the URL's in there to match the new site so that wordpress can (a) create new url's correctly and (b) interpret the new site urls too.
After amending it, ours looked like this:

Simple enough to do... So we now have a fully functioning Wordpress blog sat inside the main http://www.babylovesorganic.co.uk site which is written in ASP.NET. The last step is to tell visitors to the old blog site that we've moved address.
Redirect all old site links to the new location.
This needs some configuration changes to the original URL (so in our example blog.babylovesorganic.co.uk). As we had this site in IIS before, the config changes discussed here are for managing a 301 redirect in IIS.
Creating 301 redirects for IIS (to another site and directory):
- On the original site, click the "URL Rewrite" option in the IIS section of options shown.
- On the right hand pane, click "Add Rule(s)...".
- In the Add Rule(s) dialog, select "Blank Rule" and click "Ok"
-
We're now about to tell IIS how to handle requests to the blog.babylovesorganic.co.uk domain. We set this as shown in the following diagram (explanation below):

Settings explained:- Requested URL: Matches Pattern (means we match what is in the Pattern field... its a test to see if we should redirect)
- Using: Regular expressions: A form of testing how we match.. these can be really complex but ours is a simple "match everything"!
- Pattern: Set to ".*" which means match any URL (the URL matching is the bit of the URL after the site: blog.babylovesorganic.co.uk/)
- Action Type: When we have a match, what should we do - we want to Redirect to our new site (http://www.babylovesorganic.co.uk/blog/)
- Redirect Type: Permanent (301) is the response that we send to the requesting browser. A web browser will automatically jump to the Redirect URL, search engines will update their records to just request the new URL in future.
- Redirect URL: Where do we want to go to - so the new server url. The {R:0} is a bit of special code for IIS which means put any part of the url on the old site on to the new one, so: http://blog.babylovesorganic.co.uk/stuck-like-glue/ will automatically map to http://www.babylovesorganic.co.uk/blog/stuck-like-glue/
- Try it... use the two urls above
Finished
That's it done, the old URL will now link to the new site automatically, the new site is still a fully functioning wordpress sub-site using php in an IIS application within the main ASP.NET driven site.


