@madpilot makes

WordPress Hack: Changing your permalink structure without upsetting Google

WordPress has the ability to generate permalinks, which is great for Search Engine Optimisation. But what can you do if you need to change between them? Changing them in WordPress isn’t a problem – you go to the “Options” tab, click permalinks, and select a new one. However! If others bloggers have linked to your posts, or a search engine has already indexed your blog, their links will break.

With a little bit of .htaccess trickery you easily* change between the different options without breaking your old links!

Why the star next to the “easily”? If you have a lot of posts, it could take a while, but read on….

Out of the box you have three options (There is a fourth, but if you use that option, you probably don’t need this guide!):

The WordPress permalink options

In terms of SEO, The best option is Date and name based – having the title of the post should give a higher ranking. Next best is Numeric, but only because it gets rid of the &p=123 part from the URL. Luckily moving from Default and Numeric to Date and Time is easy!

If you are moving from Default to one of the other options, then there is nothing else to do – WordPress automatically responds to this style of this URL regardless of what option is selected.

There are two ways of moving from the Numeric Option to one of the other options – the quick way and the right way!

The Right way

The right way uses a permanent redirect (using Apache’s mod_alias module) for each blog entry – this will tell search engines that the page doesn’t exist any more and that they should index the new page instead. Unfortunately, this doesn’t update links of other peoples pages, so you will need to leave the hack for the life of the blog.

Open up the .htaccess file and add the following BEFORE the # BEGIN WordPress line:

<li class="li1">
  <div class="de1">
    RedirectPermanent /blog/<span class="nu0">2007</span>/<span class="nu0">02</span>/<span class="nu0">05</span>/this-is-my-blog-post /blog/?p=<span class="nu0">123</span>
  </div>
</li>

<li class="li1">
  <div class="de1">
    RedirectPermanent /blog/archive/<span class="nu0">123</span> /blog/?p=<span class="nu0">123</span>
  </div>
</li>

<li class="li1">
  <div class="de1">
    <IfModule>
  </div>
</li>

You will need to dig into the database to find what ID number corresponds to each post. This is tedious even for a small number of posts, so I prefer the quick way. The IfModule line check to see if the mod_alias module is installed. The first RedirectPermanent link shows an example of changing from the Date and Title option. The second line shows how to change from the Numeric option.

The Quick way

The quick way uses Apache’s mod_rewrite module to rewrite the URL – as such it will only work when converting FROM numeric mode. If you need to convert from Date and Name to numeric, you have to user the Right way. Drop the following code BEFORE the # BEGIN WordPress line:

<li class="li1">
  <div class="de1">
    RewriteEngine On
  </div>
</li>

<li class="li1">
  <div class="de1">
    RewriteBase /blog/
  </div>
</li>

<li class="li1">
  <div class="de1">
    RewriteRule ^archives/<span class="br0">(</span><span class="br0">[</span><span class="nu0"></span><span class="nu0">-9</span><span class="br0">]</span>+<span class="br0">)</span> /blog/index.php?p=$<span class="nu0">1</span>
  </div>
</li>

<li class="li1">
  <div class="de1">
    <IfModule>
  </div>
</li>

The IfModule line makes sure mod_rewrite is enabled, the next link tells Apache to turn mod_rewrite on. The RewriteBase line tells apache to automatically prepend /blog/ to all rewrite tests. The second last line is the meat and potatoes: it tells apache to rewrite any url that looks like /blog/archives/[one or more numbers] to /blog/index.php?p=[the numbers].

I would highly recommend using the Date and Name option – thankfully converting to that option is the easiest to do!

The clothes are back on

Was it good for you?

Naked for a good cause

“Hey Myles!” I hear you ask, “What’s with the bland website? It was so colourful before”.

Well my fine feathered friends, today is CSS Naked Day an exhibit of what what happens when you correctly separate content from presentation. YOu SHOULD still be able to make sense of what a website is trying to say without relying on CSS to pretty things up. How do I rate?

If it has freaked you out to much, it’ll be back to normal tomorrow.

Mobile Web and getting copy right

Hear ye! Hear ye! Tomorrow is the monthly Port80 meeting, and we have episode III of the Port80 mini-talk franchise. This month, we have Nick Cowie talking about “The mobile web: why you should care” and Bronwen Clune with “Getting copy right”.

I’m looking forward to hearing from both these guys, and you should too! So if you would like to come along, just turn up to the Velvet Lounge in Mt Lawley at about 6pm. There is even free food – what more reason do you need? None. I’ll see you then.

If you think you have what it takes to do a 10 minute presentation to a bunch of like minded web people, then please drop me a line – we are a friendly bunch, who like long walks along the beach and love to meet new members who are willing to share.

Westcoast bloggers website revamp

Some of you may have noticed the West Coast Bloggers button on the sidebar of my blog. Well after some design magic from Si and CSS mastery from Nick, we are happy to announce the new website!

Oh, and you might notice the new twitter widget in thee sidebar too. I’ve succumbed. We’ll see how long it lasts.

WGET: The poor man’s SVN – Using Capistrano on a host with out subversion

I have a client for whom I created a CakePHP-based website for over a year ago. He has since come back to me and asked for a number of changes. I thought I would take the opportunity to use capistrano, because there are a number of steps I always had to perform when updating his site and I hate having to do them manually.

I went about checking all the necessary requirements on his host:

  1. SSH access – check! The host his site was on allows an SSH connection which is required by capistrano
  2. Apache follows symbolic links – check! Because capistrano uses a symbolic link from the document root to the latest version of the site, Apache needs to be able to follow them (i.e the site’s apache configuration needs FollowSymLinks enabled)
  3. Has svn installed – fail! This could be a problem. Capistrano by default checks out the HEAD revision from the defined repository – if it can’t use SVN, it can’t download the latest version of the site.

So close! If only I could download the HEAD revision of a site using a common command line system. I thought about writing a SVN-to-web interface, that would check out the latest version and post them as a website, but then I remembered SVN does that out of the box using the SVN apache module. Thankfully, when I was building my development machine, I made I installed the SVN module – it was now time to use it!

First I needed to tell Apache serve up the a copy of the SVN repository. Dropping the following into the Apache config file did the trick:

<li class="li1">
  <div class="de1">
    <ins class="in"> </ins> DAV svn
  </div>
</li>

<li class="li1">
  <div class="de1">
    <ins class="in"> </ins> SVNPath /path/to/svn/repository
  </div>
</li>

<li class="li1">
  <div class="de1">
    <ins class="in"> </ins> AuthType Basic
  </div>
</li>

<li class="li1">
  <div class="de1">
    <ins class="in"> </ins> AuthName &#8220;My Secret SVN Repository&#8221;
  </div>
</li>

<li class="li1">
  <div class="de1">
    <ins class="in"> </ins> AuthUserFile /path/to/a/.htpassword/file
  </div>
</li>

<li class="li1">
  <div class="de1">
    <ins class="in"> </ins> Require valid-user<span class="sc3"></span><span class="re1"><span class="re2" /></span>
  </div>
</li>

<li class="li1">
  </Location>
</li>

For those playing at home, replace /url/you/would/like/to/access with a nice easy path – this is the URL you will access to download the files, replace /path/to/svn/repository with the actual physical path to your repository and create a .htpassword file so you can limit access to the repository by using the htpasswd2 command: htpasswd2 -c /path/to/a/.htpassword/file username would work in this case (After substituting a username and real path, of course)

If you point you browser to the URL you just setup, you should see the root directory of the repository, after you enter the username and password you setup. Congratulations! You are basically there. Now you just need to reconfigure your capistrano to use wget instead of svn. I do this by overriding the deploy method – because I’m not using rails for this project, the paths and shard folders are different anyway. If you are using rails, you might need to have a look at the original recipe file and replace the svn command with the one below.

<li class="li1">
  <div class="de1">
    <ins class="in"> </ins> <ins class="in"> </ins> <ins class="in"> </ins> <ins class="in"> </ins> run <span class="st0">&#8220;wget &#8211;user=#{wget_user} &#8211;password=#{wget_pass} -m &#8211;cut-dirs=4 -nH -P #{release_path} -q -R index.html #{repository}&#8221;</span>
  </div>
</li>

<li class="li1">
  <div class="de1">
    <ins class="in"> </ins> <ins class="in"> </ins> run <span class="st0">&#8220;ln -nfs #{release_path} #{current_path}&#8221;</span>
  </div>
</li>

<li class="li1">
  <div class="de1">
  </div>
</li>

<li class="li1">
  <div class="de1">
    <ins class="in"> </ins> <ins class="in"> </ins> <ins class="in"> </ins> <ins class="in"> </ins> run <span class="st0">&#8220;rm -rf #{release_path}/app/webroot/files&#8221;</span>
  </div>
</li>

<li class="li1">
  <div class="de1">
    <span class="kw1">end</span>
  </div>
</li>

The only modification to that line is the number after the –cut-dirs switch – it should be equal to the number of directories in the URL. In our example the URL is /url/you/would/like/to/access so –cut-dirs it needs to be equal to 6.

The last thing to do is to setup the wget_user and wget_pass variables to be equal to the username and password you created using htpasswd2.

That should do it! You can now deploy to a server that is sans SVN!

Caveats: Because of the way the SVN module and WGET work, I’ve had to not include he downloading of index.html (Basically WGET treats the directory listing as a page, and will output it as index.html) so this technique will not work if you have any pages called index.html in your structure. Work around: Rename all instances of index.html to index.htm

You might get some weird results if some one checks in code at the same time as you do a deploy – unless you have a bucket load of developers working on your system and you have no communication between developers, this is pretty unlikely.

(Names have been changed to protect the innocent)

When too much web is never enough…

What a week in web (well for me anyway). Kay, Miles and myself were invited to a Tuesday morning breakfast put on by the Perth Conference Bureau. The reason? The PCB gives out grants to help start; and to help bid for conferences which is of great interest to us as AWIA committee members. Anyway – the exciting part: There was a $2000 door prize, which can be used by the winner to attend any conference in Australia. Guess who won? That right! Me! So it looks like Web Directions 07 is now on the cards! So thank you Rebecca for inviting us! There will be no doubt much shenanigans to be had.

Tonight was the inaugural Dinner 2.0 , graciously organised by Bronwen of PerthNorg fame. Some how my little ol’ time tracker got enough attention to garner me an invite. It was the who’s who of the Perth Web 2.0 fraternity: Scouta, Buzka and Minti all had representatives come along. It is great to see Perth startups who are getting recognition from the industry, it really gives me hope that our remote little city hasn’t, for once completely missed the boat on something cool.

Good times had by all! Bronwen was taking happy snaps so I’m sure they will appear on Flickr soon enough.

One computers, one PocketPC and some funky software

I recently wrote about MaxiVista – some software which allows you to turn an old laptop into a  second monitor. I still use it at work everyday to get three screens of happiness. However , what to do at home? I’ve only got two screens  at home and frankly it makes me sad. As far as I’m concerned three monitors is the holy grail of productivity.

My old Compaq iPAQ was sitting next to my laptop looking at me all forlorn – I haven’t used it much lately, now my phone does everything it used to do, so it was just sitting there using electricity. I thought to my self

Yes, this is the sort of thing I think about. Since I only use the third monitor for Getting Things Done, such as my scheduling sheet and my time tracking, the smaller screen would actually do the job. Even Synergy would have done the job, as it would have allowed me to easily edit a Pocket Excel document, and 88 Miles works on PocketPC. Alas, Synergy for PocketPC doesn’t exist (no suprises there).

What does exist though, is SideWindow by Innobec. Seriously, they have created a piece of software that, just like MaxiVista allows you to extend your desktop to another computer – except this time the other computer is you PocketPC! Crazyness.

My PocketPC displaying 88 Miles via SideWindow

Now unfortunately my PocketPC doesn’t have WiFi, only Bluetooth so the connection is a little slow (and flaky), but it works! If does discconect for no reason occasionally, but I suspect this is more to do with my dodgy networking hack (I connect my iPAQ to my server via bluetooth and BlueZ, which in turn connects to my laptop via WiFi.).

SideWindow has a screen rotate feature built in, so you can run your new screen at a more natural landscape layout, rather than the less then useful portrait. Obviously 320×240 pixels isn’t really much real estate to gain, so the clever people at Innobec allow you to scale the window to fit more in (right up to 1024×768!) The more you scale the less readable things get – I’ve found 640×480 is a nice comprimise between readability and speed, however if you have a fast network connection you might get away with a higher resolutions.

It’s $15 to buy, and probably isn’t for everyone, but it’s still on of those “Cool” things to show off to your geek friends.

Calling future speakers!

There has been a lot of debate recently about diversity in Web conferences. It is a topic that seems to rear it’s head on a semi-regular basis. As some of the players in the conference circuit have pointed out, maybe we as potential speakers can make the conference organisers’ lives a bit easier.

It is hard to encourage diversity when the pickings are thin – this isn’t to say that the talent from all realms isn’t out there, maybe the people who put on the conferences just haven’t heard about them?

Kevin Lawver has blogged about How to Get to Speak at Web Conferences and point #2 has given the inspiration for this post. Below are a list of some of the events which encourage people to get up and speak about what they love. The list is Australian-centric, mainly because that is the circles I hang with, but I would love to hear of similar things going on around the world (Hint: leave a comment and sell your event!).

So maybe you, oh humble reader, should sign up to a event near you and get your name out there – you never know who might be listening.

  1. AWIA Mini-talks – Ok, I have a vested interest in these because I organise them… Currently Perth based, but AWIA is looking to expand them Australian wide. Two speakers get 10 minutes to speak on a topic of their choice on the first Wednesday of the month. Check out the podcasts.
  2. WebJam – The WebJam organisers have just announced a second WebJam event which is on in a couple of days. WebJams are even more fasted paced – 16 speakers get three minutes!
  3. BarCamps – These “Un-conferences” encourage collaboration and knoledge share – they provde a great opportunity to speak in front of a group and show others what you know. There are BarCamps coming up in Sydney, Melbourne, Canberra and Adelaide next week – Check out the Wiki web site for details of who you can get in contact with.
  4. Melbourne (and soon to be Sydney) based Tequp is kind of similar to BarCamps, except they are weekly (And I thought organising monthly meet ups was hard!)
  5. The web standards group will often have speakers at their meetings, and I’m sure you local organiser would be more than accommodating.
  6. A number of big conferences have experimented with open-mic type session: The Future of Web apps had one, New Zealand based Webstock has it’s 8×5 seminars which looks like it is something similar.

Not a bad list, but I am sure I’ve left off heaps and heaps – I want this list expanded people!!!

Edit: SomeoneMeri Williams has created a wiki aimed at mentoring people that want to get into the speaking biz.

The new AWIA (formally known as Port80) Website is live!

After a number of late nights and long hours, the volunteers on the AWIA committee have flick the big red switch on the brand-spanking new AWIA website.

The new AWIA Website{.imagelink}Thanks to Adrian Lynch for the design and Alex Graham for the HTML/CSS trickery – the site looks great!

My contribution was the Ruby on Rails powered membership system and podcast section (As a added benefit, you get to hear my dulcet tones on the first set of Port80 Mini-talk podcasts). The membership system now allows members greater control of their accounts and uses a secure credit card facility, rather than a third party payment site. If you are an existing member, you should have received a email with your password.

This is the next step in promoting the new AWIA brand. The year looks very exciting for AWIA, with plans for another Ideas event, the WA Web Awards and perhaps some other events. It also looks like the Brisbane and Adelaide chapters will be starting up this year as well. If you aren’t a member and you in the Australian Web Industry, maybe it is time to join up?

So what do you think?

Previous Next