nada man, igualito, te pongo la clase completa de seo para que la chequees y el link donde pasa la url
class.seo.php
Código PHP:
<?php
class SEO {
/*
Method to replace characters not accepted in URLs
*/
function str_replace($scapeURL) {
$p = array('-');
$r = array(' ');
$s=str_replace($p, $r, $s);
$s = strtolower($s);
return $scapeURL;
}
function scapeURL ($text) {
// Tranformamos todo a minusculas
$text = strtolower($text);
//Rememplazamos caracteres especiales latinos
$find = array('á', 'é', 'í', 'ó', 'ú', 'ñ');
$repl = array('a', 'e', 'i', 'o', 'u', 'n');
$text = str_replace ($find, $repl, $text);
// Añaadimos los guiones
$find = array(' ', '&', '\r\n', '\n', '+');
$text = str_replace ($find, '-', $text);
// Eliminamos y Reemplazamos demás caracteres especiales
$find = array('/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/');
$repl = array('-', '-', '-');
$text = preg_replace ($find, $repl, $text);
$text = trim($text);
return $text;
}
function cleanurl($string)
{
$cleanurl = strtolower($string);
$patterns = array('/[^a-z0-9\s]/', '/\s\s+/', '/\s/', '/^-/', '/-$/');
$replacements = array(' ', ' ', '-', '', '');
$cleanurl = preg_replace($patterns, $replacements, $cleanurl);
return $cleanurl;
}
/*
Make rich links
*/
function categoria ($categoria_id) {
$scape_categoria_id = $this->scapeURL($categoria_id);
$url = 'http://127.0.0.1/alpezmed/web/productos/'.$scape_categoria_id.'.html';
return $url;
}
function subcategoria ($subcategoria_id) {
$scape_subcategoria_id = $this->scapeURL($subcategoria_id);
$url = 'http://127.0.0.1/alpezmed/web/productos/'.$scape_subcategoria_id.'.html';
return $url;
}
function nombre ($nombre) {
$scape_nombre = $this->scapeURL($nombre);
$url = 'http://127.0.0.1/alpezmed/web/productos/'.$scape_nombre.'.html';
return $url;
}
/*
Make URL with special characters
*/
function makeProductURLScape ($categoria_id) {
$cleanurl_categoria_id = $this->cleanurl($categoria_id);
$url = 'http://127.0.0.1/alpezmed/web/productos/'.$cleanurl_categoria_id.'.html';
return $url;
}
}
class Redirect extends SEO {
/*
Redirects URL
*/
function categoryProductUrl() {
//Get URL
$redirected_url = $this->getCategoryProductUrl();
//301 Redirection
if ("'http://127.0.0.1/" . $_SERVER['REQUEST_URI'] != $redirected_url) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirected_url);
exit();
}
}
/*
Get keyword-rich URL
*/
function getCategoryProductUrl() {
//Get id and category product
$categoria_id = $_GET['categoria_id'];
$subcategoria_id = $_GET['subcategoria_id'];
$nombre = $_GET['nombre'];
/*
If you have a database
*/
$categoria_id = "";
$subcategoria_id = "";
$nombre = "";
//Keyword-rich URL
$url = $this->categoria($categoria_id, $subcategoria_id, $nombre);
return $url;
}
/*
Remove index.php using 301 redirection
*/
function removeIndexUrl() {
//if the request contains index.php redirect
if (preg_match('#(.*)index\.(html|php)$#', $_SERVER['REQUEST_URI'], $captures)) {
// 301 redirection
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $captures[1]);
}
}
}
?>
categoria_show.php
Código PHP:
<?php include('../conexion/conectar.php');?>
<?php require_once '../class.SEO.php';
$oUrl = new SEO;
$oUrl = new Redirect();
$result = mysql_query("SELECT * FROM categorias ORDER BY categoria_id ASC ");
$filas = 5;//o las filas que quieras que tenga la tabla como máximo
$columnas = 4;//o las columnas que quieras
$final = 0;
echo "<table>";
for($i=1;$i<=$filas && $final==0;$i++){
echo "<tr>";
$n = 1;
while(($n%($columnas+1)) != 0){
echo "<td>";
if($row = mysql_fetch_array($result)){
echo "
<table width='136' border='0' cellpadding='0' cellspacing='0'>
<!--DWLayoutTable-->
<tr>
<td width='128' height='157' valign='top'><table width='100%' border='1' cellpadding='0' cellspacing='0'>
<!--DWLayoutTable-->
<tr>
<td width='128' height='33' valign='top'><table width='100%' border='0' cellpadding='0' cellspacing='0' bgcolor='#cccccc'>
<!--DWLayoutTable-->
<tr>
<td width='128' height='33' valign='middle'>
<div align='center'>"; ?><a href='<?php echo $oUrl->categoria("$row[categoria_id]"); ?>'><?php echo $row['categoria_id']; ?></a> <?php echo "</div></td>
</tr>
</table></td>
</tr>
<tr>
<td height='97' valign='top'><table width='100%' border='0' cellpadding='0' cellspacing='0'>
<!--DWLayoutTable-->
<tr>
<td width='128' height='97' valign='top'><img src='../img/categorias/$row[img]'></td>
</tr>
</table></td>
</tr>
<tr>
<td height='19' valign='top'><table width='100%' border='0' cellpadding='0' cellspacing='0' bgcolor='#cccccc'>
<!--DWLayoutTable-->
<tr>
<td width='128' height='19' valign='top'><div align='right'><a href='subcategoria.php?categoria_id=$row[categoria_id]' target='_self'>mas...</a></div></td>
</tr>
</table></td>
</tr>
</table> </td>
<td width='8'> </td>
</tr>
<tr>
<td height='7'></td>
<td></td>
</tr>
</table>
";
}
echo "</td>";
$n++;
}
echo "</tr>";
}
echo "</td></tr></table>";
?>
htaccess
Código:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^categoria.html categoria.php
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)\.html$ subcategoria.php?categoria_id=$1 [L]
RewriteRule ^(.*)\.html$ producto.php?subcategoria_id=$1 [L]
RewriteRule ^(.*)\.html$ detalle.php?nombre=$1 [L]
<files .htaccess>
order allow,deny
deny from all
</files>