In my ongoing saga of moving from MediaWiki to Jekyll, I decided to be smart and rename all my URLs.
Stop.
I know that’s the worst thing you can do. Please put down the pitchforks. I didn’t do this without redirections and I didn’t do it without deep thought. You see, the issue with MediaWiki is that it was a pretty flat file representation of the site. This doesn’t have to be the case. You can choose to put pages as sub-pages on MediaWiki very easily, but few people do. I didn’t. That means I had around 1000 pages that, in Jekyll land, would all be in one folder. And that sucked. Like I mentioned before, I made Collections.
This meant I was moving from example.com/PAGE
to example.com/folder/PAGE/
(and yes, the backslash matters, MediaWiki doesn’t do that). Now, from a structural standpoint, this makes a lot more sense. You want to have a collection of interviews, you have example.com/interviews/year/interviewname/
and that’s ridiculously easy to understand. But. When you’re moving from no structure to some structure, you have to accept a bit of a loss.
So here’s how to redirect sanely:
- Make a list of what has a direct relation to a new page
- Look at your page visits to see what’s hit the most and make sure that’s redirected
- Have a catch-all at the end
That’s it! Three simple steps to do it. But how did I do it?
On the Wiki, I had a whole subsection called “Encyclopedia” which had all my internal documents like the about page, the policy pages, and so on and so forth. Those were all moved to the WordPress blog. Most had a new page, but the category itself did not so I added this the .htaccess in root:
Redirect 301 /wiki/Category:Wiki / Redirect 301 /wiki/Encyclopedia:About /about/ Redirect 301 /wiki/Encyclopedia:Policy /policy/ RewriteRule ^wiki/Encyclopedia:Copy(.*)$ /copyrights/ [L,R=301] RewriteRule ^wiki/Encyclopedia:Terms(.*)$ /terms-of-use/ [L,R=301] RewriteRule ^wiki/Encyclopedia:(.*)isclaimer /disclaimer/ [L,R=301]
That’s all incredibly straightforward for .htaccess rules. The first three are one-to-one direct links and the last three are with variables to handle URL strings like “Terms_Of_Use” and “Terms_of_use”, both of which were Wiki-forwarded to the correct “Terms of Use.” Similarly, I wanted to redirect “General_Disclaimer” and “Disclaimer” to one page, simplifying things.
This pattern of one-to-ones continued on through my .htaccess. Pages that I could link like that I did. But then I hit on a couple big sections, the Interviews and News Articles. Those I had, for years, broken apart into pages by year. So I cleverly used tricks remembered from changing my WordPress date permalinks to do this:
Redirect 301 /wiki/Interviews /library/transcript/ RewriteRule ^wiki/Interviews_\((.*)\)$ /library/transcript/$1 [L,R=301] RedirectMatch 301 /wiki/(News|News_Articles) /library/news/ RewriteRule ^wiki/News_Articles_\((.*)\)$ /library/news/$1 [L,R=301]
The main URLs were directed to the new main locations, but the per-year ones were sent, logically, to their new year locations. But that was the easy part. When I moved things over, I got rid of ‘character’ pages (which I had only sporadically updated anyway) and I wanted to combine a lot of the redundant pages:
RedirectMatch 301 /wiki/(The_West_Wing|West_Wing|west_wing|ww|Jed_Bartlett) /library/show/west-wing/ RewriteRule ^wiki/The_West_Wing_\((.*)\)$ /library/show/west-wing-episodes/ [L,R=301]
That’s starting to look a lot better. I did a lot of those. I tried to make them as dynamic as possible, but there were limits. In the end, I had about a dozen popular links I had to do manually. I don’t like that, but that’s the world I got myself into. I wanted to be able to redirect news and interviews to at the very least their year page, but as it turned out, I used the same naming conventions.
Redirect 301 /wiki/Yahoo_News_(01_January_2000) /library/news/2000/yahoo-1/ Redirect 301 /wiki/EOnline_(01_January_2011) /library/transcripts/2011/eonline-1/
See the problem? There’s no way to really point those around. I played with a lot of options before I ran a search my recent traffic to see what pages were popular that people were going to in the /wiki/
folder and redirected them as best I could.
Finally I had my fall back:
RewriteRule ^wiki/(.*)$ /where-has-the-wiki-gone/ [L,R=301]
This is the last rule. If anything gets through the others and down to this one, it sends them to a new page that explains where the wiki went and links to the popular pages.
The most important thing to remember in all this is to put things in order. Your .htaccess
is a top-down file. It starts at the top, it processes rules in order, until it’s done.