Hi everybody, I’m John
I’m working at a new gallery website and need some help to hide APP_ROOT from $url if it is posible.
This is the sourced code of my files:
include (‘…/appconfig/config_prezentare_galerie.php’);
/**
-
Return array of $_GET and $_POST data
-
@return array
*/
function parse_params()
{
$params = array();if (ini_get('magic_quotes_gpc') == 1) { if (!empty($_POST)) { $params = array_merge($params, stripslashes_deep($_POST)); } else { $params = array_merge($params, $_POST); } } else { $params = array_merge($params, $_POST); } if (ini_get('magic_quotes_gpc') == 1) { if (!empty($_GET)) { $params = array_merge($params, stripslashes_deep($_GET)); } else { $params = array_merge($params, $_GET); } } else { $params = array_merge($params, $_GET); } return $params;
}
// strips out escape characters
function stripslashes_deep($value)
{
$value = is_array($value) ? array_map(‘stripslashes_deep’, $value) : stripslashes($value);
return $value;
}
function dispatcher($routes)
{
// Requested URL
$url = $_SERVER[‘REQUEST_URI’];
******** this i want to remove from URL also, not only from my $routes
// Removes Apllication root from url
$url = str_replace(‘/’.APP_ROOT.‘/’, ‘’, $url);
// holds the named captures, $_POST data
$params = parse_params();
// Removes query string from $url we don't need it anymore affect routes.
// nu va mai intra in paternul de comparare a $url
$url = str_replace('?'.$_SERVER['QUERY_STRING'], '', $url);
// becomes true if $route['url'] matches $url
$route_match = false;
// loops over $routes looking for a match
foreach($routes as $urls => $route)
{
// if match found appends $matches to $params
// sets $route_match to true and also exits loop.
if(preg_match($route['url'], $url, $matches))
{
$params = array_merge($params, $matches);
$route_match = true;
break;
}
}
// if no route matched display error
if(!$route_match) {
redirect_to('error404');
//redirect_to('prezentare');
exit();
// exit('<p><h4>Warning: no route found!</h4></p>'.'<p><a href="'.WEBSITE.APP_ROOT.'">Inapoi</a></p>');
}
The above code is for my routing urls and the next code it’s for my preg_match patterns:
$routes = array(
// pagina
array(‘url’ => ‘/^prezentare\/(?P<id>\d+)$/’, ‘controller’ => ‘prezentare’, ‘view’ => ‘show’),
array(‘url’ => ‘/^prezentare\/(?P<id>\d+)\/edit$/’, ‘controller’ => ‘prezentare’, ‘view’ => ‘edit’),
array(‘url’ => ‘/^prezentare\/new$/’, ‘controller’ => ‘prezentare’, ‘view’ => ‘new’),
array(‘url’ => ‘/^prezentare\/create$/’, ‘controller’ => ‘prezentare’, ‘view’ => ‘create’),
array(‘url’ => ‘/^prezentare\/(?P<id>\d+)\/edit$/’, ‘controller’ => ‘prezentare’, ‘view’ => ‘edit’),
array(‘url’ => ‘/^prezentare\/(?P<id>\d+)\/update$/’, ‘controller’ => ‘prezentare’, ‘view’ => ‘update’),
array(‘url’ => ‘/^prezentare\/(?P<id>\d+)\/delete$/’, ‘controller’ => ‘prezentare’, ‘view’ => ‘delete’),
// homepage+ paginate
array(‘url’ => ‘/^(prezentare)?\/?(page\/)?(?P<page>\d?)$/’, ‘controller’ => ‘prezentare’, ‘view’ => ‘index’),
… and so on…
);
All I want in the final URL to not look like this “http://localhost/[B]sablonprezentare[/B]/page/1” and to look just like this “http://localhost/page/1”. The bolded word from url it came from:
define(‘APP_ROOT’, ‘sablonprezentare’);
// address of website.
define('WEBSITE', 'http://localhost/');
Any help would be appreciate.
Regards.