为什么前导斜杠与我的RewriteRule不匹配?

I hope I'm missing something silly.

I'm trying to redirect URLs using .htaccess on Apache 2.2 using the PHP 5.4 cartridge on OpenShift's free hosting service.

This matches the URI /permalink/a123 (note the lack of leading slash in the rule's filter pattern):

RewriteEngine On
RewriteRule permalink/a.*$ /permalink/b [R=301,L]

This does not match the URI /permalink/a123 (note the leading slash in the rule's filter pattern):

RewriteEngine On
RewriteRule /permalink/a.*$ /permalink/b [R=301,L]

So what stupid thing do I have wrong?

Thanks.

The URI used to match patterns in a RewriteRule are canonicalized in a per-directory context (either in an htaccess file or in a <Directory> container) by removing the leading /. So if the requested URL is:

http://example.com/web/permalink/123

And from within an htaccess file in the document root, the URI used to match rules is web/permalink/123. But within an htaccess file in the web folder, the URI is permalink/123, etc.

Thus you can't have your patterns start with a / because they're stripped from the URI in the context of an htaccess file.