Trimming the trailing slash in URLs with a 301 redirect
Why not pin this here — easier to find later, when I need it again. Search engines often treat pages like
arm1.ru/blog/yandex-upal-panika-v-twitter
and
arm1.ru/blog/yandex-upal-panika-v-twitter/
as different pages. So you end up with the same content technically living at two URLs, which isn’t great. Below the cut — code that automatically strips a trailing / via a 301 redirect, so search engines don’t end up with duplicate pages.
<?php
# strip the QUERY_STRING from REQUEST_URI
$uri = $_SERVER['REQUEST_URI'];
if ( false === empty( $_SERVER['QUERY_STRING'] ) )
$uri = str_replace( '?' . $_SERVER['QUERY_STRING'], '', $uri );
# 301 redirect when there is a trailing slash on $uri
if ( substr( $uri, -1 ) == '/' && strlen( $uri ) > 1 ) {
$queryString = '';
if ( false === empty( $_SERVER['QUERY_STRING'] ) )
$queryString = '?' . $_SERVER['QUERY_STRING'];
header( 'Location: ' . substr( $uri, 0, -1 ) . $queryString, true, 301 );
exit;
}
Recap of Apple Developers Community #7 meetup
Went to Apple Developers Community #7 today. The talks were about marketing iOS apps. Two people effectively presented — a representative from Nevosoft, who seem to crank out games on a conveyor belt, and one indie developer.
Posting to Twitter via PHP
Long meant to share my modest set of functions for posting tweets to Twitter. Maybe useful to someone — none of it came to me right away, especially the signature generation. Plus this is my attempt to lock into my head what I’ve learnt and coded. The best way to do that, I think, is to try to explain it to someone else :) Description and code below the cut.
PUT problems after upgrading CouchDB to 1.1.0
Today we upgraded CouchDB on the production server to 1.1.0. Ran into a problem — PUT requests didn’t work, returning a strange error:
[error] => unknown_error
[reason] => function_clause
I.e. we couldn’t update a single document in the database, while POST requests for creating new documents worked just fine.
It turned out that when upgrading CouchDB from an older version to 1.1.0 there are two versions of some module left in the system (it might affect several modules) — the old one and the new one. These two versions conflict with each other.
The fix was simple, although a bit weird. You need to find where the *.beam files are stored on the system (in our case it’s /opt/couchdb), delete them (if you’re nervous, you can move them aside), then go back to the CouchDB source folder and run again:
make install
Streaming audio on Mac OS X

It just so happens that in my room the speakers are on one side and the computer on the other. Running a cable from the speakers doesn’t feel like a sane idea. So — there are speakers, wi-fi, and a wi-fi-capable mobile device (in my case an iPad, but anything that can play music over wi-fi will do). I remembered that there’s a great tool called Nicecast — with one click you can set up an online broadcast. The point: stay at my desk and control the music there, but have it play on the speakers across the room. Some will say running a cable is easier, but… fuck yeah, why not over-engineer it?
A few FCKEditor settings

A note to self — for quickly setting up FCKeditor. It’s outdated and the developers are working on CKEditor instead, but CKEditor doesn’t have a free file manager, while FCKEditor does.
So this is a quick reference for getting FCKEditor up and running.