Saturday, October 31, 2009
greed in apache rewrite rules
In modern apache, mod_rewrite uses PCRE instead of your system's regexp. One thing to watch out for in rules is greediness. Basically, each matching rule will attempt to match the maximum amount allowable to satisfy a rule. This, however, is rarely what you want when using statements like (.*) in the middle of a RewriteRule. (although it's usually exactly what you want at the end of a rule).
Here's a basic demonstration (watch how $1 takes the largest possible string):
#Rewriting with two greedy capture anything statements split by a '/'
RewriteRule ^/test/(.*)/(.*)$ /foo?one=$1&two=$2 [R,L]
Results:
request
> GET /test/foo/bar/moo HTTP/1.1
response
< HTTP/1.x 302 Found
< Location: http://mspo.com/foo?one=foo/bar&two=moo
Now switch to non-greedy mode:
#Rewriting with one non-greedy capture anything followed by a greedy (see how $1 takes the smallest possible string)
RewriteRule ^/test/(.*?)/(.*)$ /foo?one=$1&two=$2 [R,L]
Results:
request
> GET /test/foo/bar/moo HTTP/1.1
response
< HTTP/1.x 302 Found
< Location: http://reallygothic.com/foo?one=foo&two=bar/moo
When using aggressive captures (.+) or (.*) in the middle of your rule, think carefully about using the ? to modify greed characteristics to make sure you get exactly what you want.
For extra testing confusion, a test with just two parameters (GET /test/foo/bar HTTP/1.1) would have shown these two rules to be exactly the same.
Here's a basic demonstration (watch how $1 takes the largest possible string):
#Rewriting with two greedy capture anything statements split by a '/'
RewriteRule ^/test/(.*)/(.*)$ /foo?one=$1&two=$2 [R,L]
Results:
request
> GET /test/foo/bar/moo HTTP/1.1
response
< HTTP/1.x 302 Found
< Location: http://mspo.com/foo?one=foo/bar&two=moo
Now switch to non-greedy mode:
#Rewriting with one non-greedy capture anything followed by a greedy (see how $1 takes the smallest possible string)
RewriteRule ^/test/(.*?)/(.*)$ /foo?one=$1&two=$2 [R,L]
Results:
request
> GET /test/foo/bar/moo HTTP/1.1
response
< HTTP/1.x 302 Found
< Location: http://reallygothic.com/foo?one=foo&two=bar/moo
When using aggressive captures (.+) or (.*) in the middle of your rule, think carefully about using the ? to modify greed characteristics to make sure you get exactly what you want.
For extra testing confusion, a test with just two parameters (GET /test/foo/bar HTTP/1.1) would have shown these two rules to be exactly the same.
Labels: apache tips
Wednesday, October 21, 2009
pkgsrc openjdk7 gets better java font support
Fonts in java have always been a challenge for everyone involved as java is supposed to provide a portable environment for programs to run- including GUI!
Java in netbsd has always been even more of a challenge, but now its font support is getting improved: font support in openjdk7 from pkgsrc
Java in netbsd has always been even more of a challenge, but now its font support is getting improved: font support in openjdk7 from pkgsrc
Labels: pkgsrc
Saturday, October 17, 2009
NetBSD gets usb device access from userland
USB device support in userland: kernel usb device driver support in rump
This already works for usb storage devices, so let's try to get some sound cards, network devices, and input devices moved into userspace.
This already works for usb storage devices, so let's try to get some sound cards, network devices, and input devices moved into userspace.
Labels: NetBSD