Permalink
Browse files

Allow to use base_uri option for url routing.

Right now, the following methods are used to determine request_uri(),
used in routing :

* u or uri GET params
* PATH_INFO (index.php/uri)
* QUERY_STRING (index.php?/uri)
* REQUEST_URI, which is just the equivalent of the two above methods
  but for webservers which doesn't set PATH_INFO or QUERY_STRING

The problem with this is that none is controllable via user
configuration.

This patch modify the last method to try to use option('base_uri') in
addition to the internally computed base_path. For example, if
REQUEST_URI is /app/myroute and option('base_uri') is '/app', then
request_uri() (if not other methods are used) will return '/myroute'.

The main usage of this new method will be to allow rewrite rule of
this form :

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ index.php [QSA,L]

Which is the preferred method for "pretty"-urls in Nginx.
  • Loading branch information...
1 parent 5eaebb7 commit 12955a39b57d5811b29e41ee6e4455a21a2cf0fc @sloonz sloonz committed Feb 28, 2012
Showing with 3 additions and 0 deletions.
  1. +3 −0 lib/limonade.php
View
@@ -1063,6 +1063,9 @@ function request_uri($env = null)
if($request_uri."index.php" == $base_path) $request_uri .= "index.php";
$uri = str_replace($base_path, '', $request_uri);
+ if(option('base_uri') && strpos($uri, option('base_uri')) === 0) {
+ $uri = substr($uri, strlen(option('base_uri')));
+ }
}
elseif($env['SERVER']['argc'] > 1 && trim($env['SERVER']['argv'][1], '/') != '')
{

0 comments on commit 12955a3

Please sign in to comment.