A while back I restructured my website so that this blog no longer started at the root, instead starting from /blog. This was so that I could introduce some other web apps and have a subfolder for projects etc.
One of the pains of this restructure was modifying all the links - I thought I had caught all this with a Redirector HttpModule, but recently realised that for some reason I had not caught images embedded in the posts themselves.Also it was becoming a pain having to remember to include the HttpModule in my web.config everytime I upgraded my blog (dasBlog)
I wanted it fixed properly this time, so grabbed a copy of all the XML files in my 'content' folder, copied them to a local folder and cracked open PowerShell...
I wanted every instance of www.mywebsite.com changed to www.mywebsite.com/blog - not difficult, but this would also change valid urls such as www.mywebsite.com/blog/page.aspx to www.mywebsite.com/blog/blog/page.aspx (note the /blog/blog in the url)
So I got everything I needed done with two 'one liners' in PowerShell...
dir | %{ $a = get-content $_ ; $a = $a -replace ("www.mywebsite.com", "www.mywebsite.com/blog") ; set-content $_ $a }
...and...
dir | %{ $a = get-content $_ ; $a = $a -replace ("www.mywebsite.com/blog/blog", "www.mywebsite.com/blog") ; set-content $_ $a }
All fixed...
Dear Ken,Thanks for the tip regarding replacing strings within a text file.Is there a way to specify multiple replacement strings? In UNIX SEd, you can specify the old and new string within a text file. Rather than wrting a bunch of one-liners, I was hoping to find a means to change multiple strings via a one-liner.Sincerely,Mike Ramirez
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u
Enter your email address:
Delivered by FeedBurner