[Catalyst] Re: catalyst request path and apache rewrites

William Wueppelmann william.wueppelmann at canadiana.ca
Tue Dec 22 14:03:30 GMT 2009


On 2009-12-19, at 9:30 AM, Aristotle Pagaltzis wrote:

> * William Wueppelmann <william.wueppelmann at canadiana.ca> [2009-12-18 14:40]:
>> I have the following rules configured for my virtual host in
>> apache:
>> 
>> RewriteCond %{REQUEST_URI} !^/foo/bar
>> RewriteRule ^/(.*)$ /foo/bar/$1 [PT]
> 
> Btw, this is most probably not going to affect your problem, but
> anyway, you likely want to lose the RewriteCond and instead have
> just
> 
>    RewriteRule ^/(.*)$ /foo/bar/$1 [L,PT]

I had hoped it would be simple enough to just us an Alias:

Alias / /MyApp/script/myap_fastcgi.pl/foo/bar/

It looks like the problem is that Apache doesn't handle requests the way I expected (it doesn't modify the HTTP request itself when it rewrites the path, it seems) so I've had to re-think my strategy. I'm now handling the conditional URI interpretation in my app itself: I added a prepare_path method to MyApp.pm which checks the config file for a set of host => prefix mappings and prepends the required path if the request is coming from a particular host. E.g.:

<prefix>
	http://foo.mydomain.com/	foo/bar
	http://baz.mydomain.com/	baz/bar
</prefix>

So anytime $c-request->base is 'htttp://foo.mydomain.com/' it prepends foo/bar to the path before dispatch. It turns out that this is probably a better solution, because I need this information in the config file anyway so that I know to strip out the leading /foo/bar from URLs generated by the templates when called from foo.mydomain.com, and this way, I don't have to worry about my apache config and myapp.conf in sync.

-William


More information about the Catalyst mailing list