Archive for August, 2006

Mod Rewrite Rules You Can Live With

Wednesday, August 23rd, 2006

I had some issues upgrading to the latest apache 2.0, which turned out to have apparently broken my mod rewrite rules.

As usual, my problem turned out to be a trivial fix. In httpd.conf I hadn’t merged the AllowOverride None line directly…to use mod rewrite rules in your .htaccess file correctly, this value has to be set to “All” instead of “None”.

AllowOverride All will allow you to use mod rewrite rules in your .htaccess file.

Here’s a simple test:

Open foo.html and bar.html, and add those respective words to the file. (foo.html contains “foo”, bar.html contains “bar”).

Now, open up your .htaccess file (typically, /path/to/yoursite.com/htdocs/.htaccess), and add the following mod rewrite rules:

RewriteEngine on
RewriteRule  foo.html    bar.html  [L]

Now access: yoursite.com/foo.html

You should see the word “bar” instead of “foo” in your browser.

For debugging, try enabling mod rewrite’s log level to 9.

See the mod rewrite documentation for more info and examples of mod rewrite rules.

VN:F [1.8.4_1055]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.4_1055]
Rating: 0 (from 0 votes)

Programming Cheat Sheet

Saturday, August 5th, 2006

Came across another programming cheat sheet (with examples) via digg.
The article is Programming is Hard: Let’s work to make it a little easier. and provides lots of snippets and examples from different programming languages.

VN:F [1.8.4_1055]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.4_1055]
Rating: 0 (from 0 votes)

PHP Database Programming Mistakes

Saturday, August 5th, 2006

There’s a good article from IBM about the five common PHP database problems users encounter when working with databases and php.

Some of the tips include refraining from directly access mysql php functions (this should be abstracted to a database layer, so you can swap out your database easily without having to modify the code).

Also it talks about the n+1 pattern, in which the app retrieves a list of items, then cycles through each item and grabs the relevant info for each item. In a small database, this is not a problem, but with over 1,000 records, that’s 1,000 more database queries to retrieve the info.

A lot of this recurring can be solved with database relations and normalization.

It also recommends not using more than 1 database for an entire application.

VN:F [1.8.4_1055]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.4_1055]
Rating: 0 (from 0 votes)