I'm using a front controller to handle requests on a web page about buildings.
With this URL I get a list of all buildings on the web page (Note that the word buildings with a S in the end):
/buildings
And with this URL I show a single selected building from the web page above (Note the word building without any S in the end):
/building/building-name
My question is if it's possible to also use a URL like this for a single selected building:
/buildings/building-name
I would like to use /buildings/ for the page to list all buildings and /buildings/building-name for the page to show the selected building. If this is possible, I wonder how I handle this in the htaccess file and in the PHP front controller? If I'm using buildings twice as an option in the switch case it would not work?!
Part of the htaccess file:
# Buildings (List all buildings)
RewriteRule ^buildings$ /?p=buildings [L,QSA]
#Building + id (Show a single selected building)
RewriteRule ^building/(.+)$ /?p=building&id=$1 [L,QSA]
PHP-code in index.php:
// pagecontrol
$page = isset($_GET["p"]) ? $_GET["p"] : "start";
switch($page)
{
case 'start': require_once('start.php'); break;
case 'buildings': require_once('buildings.php'); break;
case 'building': require_once('building.php'); break;
default: require_once('start.php'); break;
}
Preciate some help to solve this problem!