Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 14700

.htaccess PHP Clean URLs

$
0
0
Boas,

Eu estou a tentar usar clean Urls para um backoffice. Resulta bem quando tenho o url até à página:

Citar


Mas quando acrescento a acção, a página perde os estilos (CSS).

Citar



Eu tenho uma função para "separar" o url:
Código (PHP):
<?php
function parse_path() {
$path = array();
if (isset($_SERVER['REQUEST_URI'])) {
$request_path = explode('?', $_SERVER['REQUEST_URI']);
$path['base'] = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/');
$path['call_utf8'] = substr(urldecode($request_path[0]), strlen($path['base']) + 1);
$path['call'] = utf8_decode($path['call_utf8']);
if ($path['call'] == basename($_SERVER['PHP_SELF'])) {
         $path['call'] = '';
}
$path['call_parts'] = explode('/', $path['call']);
$path['query_utf8'] = urldecode($request_path[1]);
$path['query'] = utf8_decode(urldecode($request_path[1]));
$vars = explode('&', $path['query']);
foreach ($vars as $var) {
         $t = explode('=', $var);
         $path['query_vars'][$t[0]] = $t[1];
}
}
return $path;
}
?>

E este é o meu .htaccess:
Código :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^ main.php [L]
</IfModule>

header.php
Código (PHP):
<?php
include('../functions/functionCleanUrl.php');

$cleanUrl=array();
$path_info = parse_path();
$cleanUrl=$path_info['call_parts'];

if(isset($cleanUrl[0])){ $page = $cleanUrl[0]; }
if(isset($cleanUrl[1])){ $action = $cleanUrl[1]; }
if(isset($cleanUrl[2])){ $id = $cleanUrl[2]; }
(...)

Aqui tenho o meu main.php onde vai buscar os ficheiros dependente da página seleccionada:
Código (PHP):
<?php
include('../includes/header.php');
?>
<div id="container">
<?php
$filename = $page.'.php';
if(file_exists($filename))
{
if($page!='')
         if((isset($action)) && ($action!=''))
         include('addItem.php');
         else
         include($page.'.php');
else
         include('dashboard.php');
}
else{
include('404.php');
}
?>
</div>
<?php
include('../includes/footer.php');
?>

Obrigado!

Viewing all articles
Browse latest Browse all 14700