August 30, 2007

“works” trumps “elegance” every time

Filed under: PHP,Socialtext — Allan @ 9:51 pm

For a while now I’ve been toying with using our Socialtext server for more than just the wiki. The problem there is that Socialtext uses apache-perl with what (for me) appears to be a somewhat interesting set of mod_rewrite rules. From what I can tell, it takes whatever you bung in the URL and passes the query string through to the default mod_perl index.cgi script and that then takes care of deciding which page you get to see. Works great. So I compiled PHP into the mix and that’s when I ran into my mod_rewrite headache.

The lines

RewriteRule ^/([^/\.]+)/?$ /$1/index.cgi [R,L,NE]
RewriteRule ^/$ /index.cgi [R,L]

in the apache-perl conf files appeared to be the main cuplrits. Every time I tried to browse to a PHP script, the rewrite rule would hand it over to index.cgi and that would be the end of it. So, after creating a /php/ alias I added this rule:

RewriteRule ^/php/[\.0-9]+/(.+)$ /php/$1 [PT,L]

which allowed me to target PHP files within the alias, but as soon as I targetted a directory and not a physical file, index.cgi leapt back into the breach. Not wanting to clutter up the neatly thought out set of rewrite rules implemented by the clever people who wrote Socialtext I toiled first at writing a cunning all-encompasing rewrite rule and after failing there, at getting it to use index.php as my DirectoryIndex. No dice. I eventually gave in and added:

RewriteRule ^/php/[\.0-9]+/(.+)/$ /php/$1/index.php [PT,L]
RewriteRule ^/php/$ /php/index.php [PT,L]

the first to target directories below the /php/ alias and the second the root of the /php/ alias itself.\

So now I have 3 similar rules to achieve one thing. Elegance be damned, it works.

I’m sure there’s somebody out there who could provide a nice neat all-encompassing single rewrite rule. Feel free to share it in the comments below :)


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at

%d bloggers like this: