Tech Musings

Monday, June 18, 2007

Apache and mod_rewrite

Oh, for the love of humanity. I can't believe how much time I spent today trying to decipher the esoteric and cryptic regular expression patterns of mod_rewrite. The goal was to redirect visitors coming from a specific domain to a different or separate page from what I'm going to set as the new default. Why? Because I'm preparing to change over the default home page in my domain (mydomain.com) to a FLASH version. BUT, if visitors come from one specific domain (www.thisotherdomain.net) I want them to be redirected to the old PHP page, not the new Flash version.

Using Apache's mod rewrite module I was able to do this but only because I finally found the following helpful forum thread:

http://www.webmasterworld.com/apache/3361785.htm

Here's the example of how to write the .htaccess code for it:

Options +FollowSymlinks
RewriteEngine on
RewriteCond $1 !^old_index.php
RewriteCond %{HTTP_REFERER}^https?://([^.]+\.)*thisotherdomain\.net
RewriteRule ^(.*) http://mydomain.com/old_index.php [R=302,L]

The first rewrite condition is needed because Firefox originally complained about an infinite loop. Interesting, it was much easier to find examples on the Web for this little Apache magic when setting up a redirect based on NOT coming from a specific domain. The example above is nice because it will redirect even if the referring link is from a domain or subdomain on http://www.thisotherdomain.net. Also, it is important to remove the "$" pattern end anchor that I normally place at the end of RewriteCond statements in my .htaccess files.

Friday, June 08, 2007

OS X Default User Template

I normally create a default OS X user template when prepping a master image for deployment. The last few times I've tried this I've run into a snafu or two, so it probably makes sense for me to document it here to jog my memory the next time I do it.

First, it's important to note that I've run into problems using the instructions from Mike Bombich's site here. The last few times I followed these instructions the default user template didn't stick. In fact, I've actually had more luck with the instructions posted by Glenn Rees in this forum post.

1. Tweak your default account including setting dock, clearing cache, recent items, etc. I usually name this account "teacher."

2. Login to the machine as root (I've had problems when I did these steps under a straight admin account as sudo).

3. Create a backup of your current English.lproj template. Don't just issue a mv (move) command to rename it-- create a copy of it using ditto instead.

3. Delete the default home directory files under English.lproj in /System/Library/User\ Template/English.lproj. Don't just delete the entire English.lproj directory!

4. Issue the following commands:

:~root# cd /System/Library/User\ Template/
:~root# sudo ditto -rsrcFork English.lproj/* English.lproj.bak
:~root# sudo rm -rf /System/Library/User\ Template/English.lproj/*
:~root# sudo cp -R /Users/teacher/* /System/Library/User\ Template/English.lproj/
:~root# sudo chown -R root English.lproj
:~root# sudo chgrp -R wheel English.lproj

5. Restart, log in as admin and repair permissions before creating a new account to see if it worked.

I know the sudo commands above are redundant but I just do it as a matter of habit. Slashes and astericks shown in commands above are critical! Also, I've read in some places that permissions on the default user template aren't important but I chown and chgrp on it just to be safe.