News


Latest site news

Redirecting URLs with mod_rewrite

Posted May 12th, 2010 in Bread-crumbs by admin

If you’ve ever needed to move a web page’s location or change it’s URL but didn’t want to break external links to it as well as loose your Google juice, you can use Apache’s mod_rewrite to redirect a user’s browser automatically to the new location. Although there are many ways to do this with simple URL names it can become more challenging when using dynamic links. The question mark is a special character and escaping it doesn’t produce the desired effect when used on URLs like somepage.php?id=12&yada=yada.

When I changed my URLs to pretty human readable URLs I used the following to keep from breaking my links.

Old URL

http://www.fatofthelan.com/articles/article.php?pid=29

New URL

http://www.fatofthelan.com/technical/how-to-install-postfix-dovecot-amavis-clamav-and-spamassassin-etch/

So in my httpd.conf I added the following stanza that redirects the old URL to the new URL.

RewriteEngine  on
RewriteCond %{QUERY_STRING} ^pid=29$
RewriteRule .* /technical/how-to-install-postfix-dovecot-amavis-clamav-and-spamassassin-etch/? [R=301,L]

One word of caution. Don’t forget to add the question mark at the end of the new URL as this forces a blank query string. Otherwise, the original query string will be retained and appended to the end of the URL producing a 404 page.

mod_security missing from Debian

Posted May 8th, 2010 in Bread-crumbs by Tobias

Due to some licensing issues, mod_security was removed from Debian. To get it back you can do this. Etch users add this line to your /etc/apt/sources.list:


deb  http://etc.inittab.org/~agi/debian/libapache-mod-security/etch ./

Apt doesn’t know about this site’s gpg key so you’ll need to import it.


gpg --keyserver wwwkeys.eu.pgp.net --recv-keys  C514AF8E4BA401C3
apt-key add /root/.gnupg/pubring.gpg
apt-get  update

Now you should be able to install as before!

Mac backup with rsync

Posted May 8th, 2010 in Bread-crumbs by Tobias
I needed to backup my wife’s MacBook to our home server and have it be “1 click” easy so she’d use it. I used ssh and rsync so she could use it anywhere securely.
First I generated her ssh key:


ssh-keygen  -t dsa -b 1024 -f ~/.ssh/backup-key

Then I copied the contents of .ssh/backup-key.pub to her ~/.ssh/authorized_keys2 file on the server.
And finally, I created the following script to backup to the server:


#!/bin/sh
# This backs up Eve's data
# Backup  with this one:
rsync -avz -e "ssh -i /Users/eve/.ssh/backup-key"  --delete --stats --progress /Users/eve eve@myserver.com:/home/eve/   --exclude '.Trash' --exclude '.DS_Store'

And that does the trick. Backs up, deletes files that have been deleted on the Mac, and excludes .Trash and .DS_Store files.

Fix GPG error with debian volatile

Posted May 8th, 2010 in Bread-crumbs by Tobias

If you’re having trouble adding debian’s volatile source, this should fix it.


gpg --keyserver wwwkeys.eu.pgp.net --recv-key  EC61E0B0BBE55AB3
gpg --export EC61E0B0BBE55AB3 | apt-key add -

Then apt-get update should work fine.

Deleting old log files

Posted May 8th, 2010 in Bread-crumbs by Tobias

If you need to create a script to delete old logs based on number of days, you can use this:


find /path/to/logs/ -mtime +90 | xargs rm -rf

…and that’ll remove any thing older than 90 days.

Quickly find/replace stuff in files

Posted May 8th, 2010 in Bread-crumbs by Tobias

I had to replace a string in a bunch of files and wanted to do it quickly.
1. cd to the directory where your files live.
2. Run this:


for i in *; do perl -i -pe 's/oldtext/new better  text/g' $i; done

..or no perl? Use sed.


for i in *; do sed -e 's/oldtext/newtext/g' -i $i;  done

Convert DOS eol to UNIX eol

Posted May 8th, 2010 in Bread-crumbs by Tobias

To convert a DOS text file (end-of-line = ^M^J) to a Unix text file (end-of-line = ^J).

# apt-get install sysutils (if using Debian) 
$ dos2unix dosfile

Configure VI to return to last line in Debian

Posted May 8th, 2010 in Bread-crumbs by Tobias

To have VI(M) in Debian to act like it does in Redhat, create a file named .vimrc (Note the dot) in your home directory and add this to it:

syntax on
au BufReadPost * if line("'\"") >  0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm  $"|endif|endif

Increasing 3ware performance in Linux

Posted May 8th, 2010 in Bread-crumbs by Tobias

hdparm -t /dev/sda with my new RAID5 array was shockingly slow. I added this to my startup:

blockdev --setra 19969 /dev/sda

Much quicker
/Happy dance

Installing java on Debian – the easy way

Posted May 7th, 2010 in Bread-crumbs by Tobias

The easiest (and the best way) to install java on Debian is as follows:

1. Verify that “contrib” is listed in your /etc/apt/sources.list

deb http://debian.oregonstate.edu/debian/ stable  main contrib

2. Update APT

apt-get  install java-package

3. Go to java.com and download the latest java bin file.

4. Create the deb package

fakeroot  make-jpkg <java_file_just_downloaded>.bin

5. Install it

dpkg -i <java_youjustmade_xxxxx>.deb

6. Happy dance.