AD7six.com

Apache named parameter problem

15 May, 2007

Show comments

I just ran across a rather curious problem, which proved to be pretty fatal. I thought I'd jot a note down so I don't forget and so it can be found by others - it also forms reason #6538 why not to develop with a windows machine :).

The Problem

With a standard (1.2) cake install, the colon (:) will be used as the default separator for named arguments; if you decide to use named parameters with your root url, the url will therefore be of the form /something:somethingelse. If you are using windows with apache and mod_rewrite (I'm running with 2.2.4 for the record) you might find that you don't get what you were expecting and are instead confronted with an error message which reads:

Forbidden

You don't have permission to access /something/somethingelse on this server

This error is as you might know generated by apache, there is nothing you can do from php to resolve this problem and neither in the .htaccess file since it is generated before anything is processed at all. A look at the apache error log may well include an error message such as:

(20024) The given path misformatted or contained invalid characters: Cannot map GET /something:somethingelse HTTP/1.1 to file

After a bit of hunting around I found a relevant ticket for apache so it's a known issue.

The solution

Logically there are (at least) two ways to get around this:

  1. Don't use a named parameter as the first root level parameter. The url /index/orAnything/something:somethingelse will work fine.
  2. Use a different argument separator. e.g. just put var $argSeperator = ";"; in your app controller.

So there you have it, a small problem with a big bite if it hits you - Hope this niblet of info is of use to someone :)

Bake on!