I had a problem last week where I couldn't create a variation of a site, it just kept failing to copy certain pages. Turns out that the problem was with the layout associated with the page...the URL of the layout was pointing to a non-existent site. If you looked at the page in the pages library the name of the layout was correct, but the link pointed to a different site.
It did make some sense, as the URL was pointing to the site from which I originally imported the site, but only some pages were broken. But why only some?
What caused the problem?
I haven't had the time to re-produce the problem yet, but based on the evidence this is what I believed happened...
I created a development site (thekid.dev) which was used to create the initial build of the site. This was then exported and imported onto a test server and a new site was created (thekid.test).
stsadm -o export -url http://thekid.dev ...
This new test site was exposed to our customer over the Internet (www.thekid.test) using AAM. This test site was used to build the site hierarchy and training, during which time pages were created using both the internal URL (thekid.test) and the external URL (www.thekid.test). Everything worked fine.
I then decided that the test site had better content than the development site and so exported/imported the test site back into the development environment.
stsadm -o export -url http://thekid.test ...
Everything still worked fine.
Roll forward to last week and I wanted to re-create a variation on the development site, so I deleted the variation label and the site hierarchy. I then re-created the label and clicked 'create hierarchies'.
This is when the error occurred!
It appears some of the pages still had a layout URL which pointed to http://www.thekid.test, the AAM URL I had used on the test site...why was that?
My theory
Because of the suspicious URL (www.thekid.test) my guess is that either the export or (more likely) the import is not taking account of AAM and only fixing URLs which start with the URL specified during the stsadm export command.
I my case I exported the site using http://thekid.test and so links using http://www.thekid.test did not get fixed during the import.
How far does this go?
Does this mean that none of those links get fixed? What about HTML fields, do they get fixed? My site didn't really have any content, none that's going to stay anyway, so I haven't spotted any problems within the content, but this could be a problem!
Fixing the PageLayout URLs
Actually this was relatively straight forward. A console application which looked at each of the pages and modified the link to the layout. The code below shows the method which does all the work.
Running this application against the development site found a number of pages where the layout was broken and fixed up the link. Running it for a second time confirmed all the layout URLs were fixed.
I then tried creating the variation hierarchies again and all was fine!
You can download the project for the console application or just download the application. To run the application just run the command...
FixLayouts http://thekid.dev
The application will then visit every publishing page and ensure the URL for its layout points to the correct site.