books.next()

gav on 2002-11-09T04:42:41

Tonight I finished "Revelation Space" and found it more than worthy of it's rating of 4/5. Whilst stacking it with my other paperbacks (I really, really need to buy a bookshelf) I couldn't resist a quick count. I now have bought and read 46 since I arrived over here, a rate of two-thirds of a novel a week.

This weekend I think it's time to geek it up and get reading the Mason book and The Pragmatic Programmer.

It's interesting to read Jeremy Zawodny's take on URLs. I would like more people to apply the KISS principle (Keep It Simple, Stupid) to them. It makes sense. I found this great mod_rewrite tutorial courtesy of inluminent.


mod_rewrite

wickline on 2002-11-09T15:59:32

I'm sure you're already aware, but for the benefit of anyone who might find the article from your link, mod_rewrite does not help as much in the security department as the article might leave you to think. Just because the "simple" form of the URL is validated by Apache does not mean that your script can't get bad input. Users may still call the script at its actual location with real CGI parameters and give bad input.

Security through obscurity isn't. Always check user input in your CGI script, even if you're using mod_rewrite.

On a less negative note, here's a fun bit of rewrite to map a subdomain to a subdirectory. It would need to be changed if your filesystem/server is not case sensitive (Mac folks serving from HFS+, Windows folks, etc). Actually, it should be doing case-insensitive checks on domain names in either case. I'll leave that as an excersize for anyone who cares (translation = my bad, too lazy to fix it right now). This could be handy for folks with wildcard DNS entries who want to start making use of that namespace.
# catch foo subdomain requests (or even subdomains of foo)
RewriteCond   %{HTTP_HOST}    ^foo\.example\.com$ [OR]
RewriteCond   %{HTTP_HOST}   \.foo\.example\.com$
# which are not requests for the following specific documents
# (which we would rather have pulled from their normal paths
RewriteCond   %{REQUEST_URI}                  !^/robots.txt
RewriteCond   %{REQUEST_URI}                  !^/favicon.ico
# and which don't already point to things in the foo directory
RewriteCond   %{REQUEST_URI}                  !^/foo/
# and re-write them to point to things in the foo directory
RewriteRule   ^(.*)          http://%{HTTP_HOST}/foo/$1
 
# for added consistancy, so our resources don't end up with
# two URLs (ie: foo.example.com/foo/x and example.com/foo/x)
# catch requests which aren't in the foo subdomain
RewriteCond   %{HTTP_HOST}   !^foo\.example\.com$
RewriteCond   %{HTTP_HOST}  !\.foo\.example\.com$
# but which point to the foo subdirectory
RewriteCond   %{REQUEST_URI} ^/foo/
# and force them to the foo subdomain
RewriteRule   ^(.*)          http://foo.example.com/$1
You could do fancier things with this. I think some one already patented using a subdomain as a session ID though. Nice way to keep an ID with a session without having to re-write any links.

-matt

Re:mod_rewrite

ThatAdamGuy on 2003-02-28T05:52:58

Hi there,

I must first admit that while I'm proudly at least somewhat of a geek, I'm a perl-idiot. I know enough to upload my perl cgi scripts with the right permission, and that's about it. And as far as .htaccess... well, um, I know about basic redirects :D

That said, I humbly ask for your kind help.

I run the site smilezone.com, and I just started up a blog at blog.smilezone.com. Everything's been relatively hunky dory since I discovered and implemented this in my .htaccess file to get the subdomain to work:

---
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} blog.smilezone.com
RewriteCond %{REQUEST_URI} !blog/
RewriteRule ^(.*)$ blog/$1 [L]
---

This works fine, except for two problems:

1) It doesn't protect against people accessing my blog incorrectly via smilezone.com/blog

2) If someone goes to blog.smilezone.com/tips (without the trailing slash), they're transported to www.smilezone.com/blog/tips/ :-(

So this evening, I stumbled upon your .htaccess snippet above, Matt, and tried it out. It seems to work great, except for a DIFFERENT problem:

It redirects blog.smilezone.com to blog.smilezone.com/blog/, when I don't want the last blog there.

Thanks so much in advance for any advice you can offer :-)

Regards,
Adam