|
.htaccess - URL re-writing. -
10-25-2011, 04:36 PM
Hello guys,
I'am having problems re-writing my proto-website URLs on distant server.
My configuration runs perfectly locally on WampServer with :
1° Following re-writing rules as part of the .htaccess file located at the root of my site:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule !\.(js|ico|gif|jpg|jpeg|png|css)$ index.php [NC,L]
2° Following function url($url) : (as part of a library folder)
function url($url) {
$controller = $url['controller'];
$action = $url['action'];
$parametres = '';
foreach ($url as $variable => $valeur) {
if ($variable != 'controller' && $variable != 'action')
$parametres .= "/" . $variable . "/" . $valeur;
}
return BaseUrl . '/' . $controller . '/' . $action . $parametres . '.html';
}
3° Following getParams function : (also part of the same library folder)
function getParams() {
$chaine = '';
if (isset($_SERVER['REQUEST_URI']))
$chaine = $_SERVER['REQUEST_URI'];
$pattern = dirname($_SERVER['PHP_SELF']);
if ($pattern == '/'
)$pattern = '';
$replacement = '';
$chaine = substr($chaine, strlen($pattern));
$pattern = '/\.(php|htm|html)$/';
$replacement = '';
$chaine = preg_replace($pattern, $replacement, $chaine);
$pattern = '/\//';
$parametres = preg_split($pattern, $chaine);
if (!isset($parametres[1]))
$parametres[1] = '';
if (!isset($parametres[2]))
$parametres[2] = '';
$params = array(
'controller' => $parametres[1],
'action' => $parametres[2],
);
for ($i = 4; $i < count($parametres); $i+=2) {
$params[$parametres[$i - 1]] = $parametres[$i];
}
return $params;
}
I also tried adding RewriteBase / but it did not change anything.
Any idea of what could be missing to make this work on distant server ?
Thks+regards,
Pascal.
|