Shared Know How

Howto: fix, find, use, make & do it guide

Archive for the ‘Other stuff’ Category

.htaccess redirect to maintenance – under construction page

author Posted by: Tim on date Jan 17th, 2011 | filed Filed under: Other stuff

For simple redirect while doing maintenance on websites like upgrades or emergency fixes I put a site in maintenance by adding the next few lines to my .htacces

RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
RewriteCond %{REQUEST_URI} !(\.(gif|jpg|css)$|^/maintenance\.html$)
RewriteRule ^(.*)$ /maintenance.html [R=302,L]

Ofcourse change the 123\.123\.123\.123 to your ip address and create a maintenance.html. This .htaccess will still serve images and css normally so you can use them in your maintenance page.

If you want to add more ip adresses just duplicate the line: RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123 and change the ip.

Share printer with Airprint under Linux/Ubuntu 10.04

author Posted by: Tim on date Nov 22nd, 2010 | filed Filed under: Other stuff

Getting Airprint printer sharing to work under linux is fairly simple.

First off all you need to get your printer working under linux using Cups and make sure you have pdf support (apt-get install cupsd cups-pdf). I won't get into detail howto configure cups. This will be different from printer to printer and pretty well described on the internet.

  • Download the script to  the script to generate an Avahi daemon config file provided by tjfontaine:

git clone (apt-get install git - if you don't have git yet)

  • To run this script you need python and python-cups:

apt-get install python python-cups

  • run the script:

cd airport-generate/

  • copy the created files to your avahi services config directory:

cp *.service /etc/avahi/services/

After this you should be ready to go. I still did get one error in my cups error log:
Request from "fe80::7ec5:37ff:fe09:62df%eth0" using invalid Host: field "office.local"

To get this working I still needed to add one line in /etc/cupsd.conf  :
ServerAlias *


Optimize your PHP website performance

author Posted by: Tim on date Apr 16th, 2010 | filed Filed under: Other stuff, php, programming, webserver

Optimize your PHP website by making sure you use the following tricks

The list

Optimize front-end

  • Combine CSS files as much as possible
  • Combine Javascript files as much as possible
  • Always place a favicon.ico (saves needless 404 request and file searches)
  • If you use a lot of small images for your website make use of CSS Sprites
  • Use GZIP compression

Optimize PHP

  • Install APC (Alternative PHP Cache). This will speed your php up a lot
  • if you don't use .htaccess or have control over the server remove .htaccess ability and set any options in your apache virtual host file.
  • don't use current directory (".") in your include path but instead link directly to files in your code: include("./example.php")
  • Watch how many include paths you have. It will search in every folder for to find include file.
  • use persistent mysql connection (mysql_pconnect)

This list is based on the presentation of Rasmus Ledorf at Campus Party 2010 - Out of this e've compiled a small checklist of things to do when you create a php website. This will make sure you will use all the simple tricks to make your website and PHP code to run fast. Further information on how to benchmark this look at the presentation of Rasmus.