From eb22bcc7548d1b1025a3832aa4555792729d11b0 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 13 Jul 2012 22:49:37 +0200 Subject: Add routing front/back ends This adds a URL mapping library that can be used to implement virtual paths. Also, "web/html/index.php" is moved to "web/html/home.php" and "web/html/index.php" becomes a routing front end that maps virtual paths to corresponding files. To enable the virtual path feature, all requests need to be redirected to the "index.php" routing script. If you use lighttpd, following rewrite rule can be used: url.rewrite = ( "^(.*)$" => "/index.php/$1" ) A similar rule can be used for Apache (using mod_rewrite). Note that the current routing front end only works if PATH_INFO is provided. Signed-off-by: Lukas Fleischer --- web/lib/config.inc.php.proto | 4 ++++ web/lib/routing.inc.php | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 web/lib/routing.inc.php (limited to 'web/lib') diff --git a/web/lib/config.inc.php.proto b/web/lib/config.inc.php.proto index 1e2699e3..fee1022a 100644 --- a/web/lib/config.inc.php.proto +++ b/web/lib/config.inc.php.proto @@ -51,3 +51,7 @@ $DISABLE_HTTP_LOGIN = true; # Web URL used in email links and absolute redirects, no trailing slash $AUR_LOCATION = "http://localhost"; + +# Use virtual URLs -- to enable this feature, you also need to tell your web +# server to redirect all requests to "/index.php/$uri". +$USE_VIRTUAL_URLS = true; diff --git a/web/lib/routing.inc.php b/web/lib/routing.inc.php new file mode 100644 index 00000000..0d940a23 --- /dev/null +++ b/web/lib/routing.inc.php @@ -0,0 +1,39 @@ + 'home.php', + '/index.php' => 'home.php', + '/packages' => 'packages.php', + '/register' => 'account.php', + '/accounts' => 'account.php', + '/login' => 'login.php', + '/logout' => 'logout.php', + '/passreset' => 'passreset.php', + '/rpc' => 'rpc.php', + '/rss' => 'rss.php', + '/submit' => 'pkgsubmit.php', + '/tu' => 'tu.php', + '/voters' => 'voters.php', + '/addvote' => 'addvote.php', +); + +function get_route($path) { + global $ROUTES; + + if (isset($ROUTES[$path])) { + return $ROUTES[$path]; + } else { + return NULL; + } +} + +function get_uri($path) { + global $USE_VIRTUAL_URLS; + global $ROUTES; + + if ($USE_VIRTUAL_URLS) { + return $path; + } else { + return get_route($path); + } +} -- cgit v1.2.3-24-g4f1b