Short Tip: Change Serendipity URLs

Friday, May 11. 2007, 07:05
Up until recently, I had URLs of the form /item/number, which is due to the reason that this was the URL-naming-scheme of bblog, an ancient blogging software I used years back. Now serendipity supports URLs with the title (minus problematic charakters), which is much better for search engines, because they often rate words that appear in the url better. Now, changing the URL after years of blogging doesn't seem appropriate (probably hundreds of links, trackbacks, bookmarks), so I needed some migration path. Serendipity doesn't support two url schemes out of the box, so I hacked some bash to do the trick. This will generate (after changing the url) forward rules (add them to .htaccess after the s9y-stuff), which send a »moved permanently«-answer. This has do be done only once, as there won't be links on new articles with the old scheme.
It's a fast hack and it probably doesn't fit in other situations without changes, but it's a nice example how fast you get somewhere with some bash and sed magic:

for i in `seq 1 31`; do
wget --quiet -O - http://www.hboeck.de/archives/P$i.html|grep serendipity_title | \
sed -e 's:^.*href="\([^"]*\)">.*$:\1:g' | \
sed -e 's:^/\w*/\(\w*\)-.*:RewriteRule ^item/\1 \0 [L,R=301]:g'
done

Trackbacks

No Trackbacks

Comments
Display comments as (Linear | Threaded)

Thats exactly the same thing, I read yesterday evening and the same thing I want to change the next days in my Drupal software. Hope, I will find a solution, which is as good as your one ;)
#1 Eichi (Link) on 2007-05-12 12:12
Since 3.0 Bash knows about a sort of range builtin, which is written that way:
{0..10}
Think that's a bit more unobtrusive than `seq`
#2 Lars Strojny (Link) on 2007-05-13 18:32
Very nice blog. I like it.
#3 DNVC (Link) on 2007-05-31 18:02

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.