Cita:
Iniciado por reyvi
MIra mano lo ideal es crear un campo en la tabla de la Bd que se llame como ams te guste en este caso url_amigable (por poner un ejemplo)
debes de cojer el titulo de la noticia cuando la insertas y hacer una cadena para que te reemplase todos los caracteres especiales, espacio, etc por _ o - como mas gustes y el resultado de esa cadena es el del campo url_amigable en la pagina notica.php lo que debes es hacer una consulta donde esta va a mostrar todo el contenido de la consulta donde el parametro url = a $_Get['url']
mas o menos asi
Código PHP:
$url =$_GET['url']
$consulta = "SELECT titulo, noticia FROM mi_tabla WHERE url_amigable ='$url'";
luego en el .htaccess
Código:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^noticias/(.+)\.htm noticia.php&url=$1
Espero te sirva, yo lo tengo asi y me funciona la las mil maravillas
Salu2
reyvi
Hola, gracias por tu respuesta, lo estoy probando como dices pero sigue sin recibir la variable, te pongo el código a ver si puedes ver algún error, gracias.
index.php
Código PHP:
<?
include("dinamic/conex_as.php");
$conexion=mysql_connect($host,$usuario_db,$pass_usuario_db);
$seldb=mysql_select_db($basedatos);
//Hago la consulta
$sop = "SELECT * FROM noticias ORDER BY idnoticia DESC ";
//Guardo el resultado
$result = mysql_query($sop);
while($lista=mysql_fetch_array($result)) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Noticias</title>
</head>
<body>
<a href="<?=$lista["url"];?>" title="<?=$lista["titulo"];?>">Ver noticia Completa</a>
</body>
</html>
<?
}
?>
Noticia.php
Código PHP:
<?
include("dinamic/conex_as.php");
$url = $_GET["url"];
$caracteresespeciales = array(" ", "/", "*", "!", "$", "%", "&", "/", "(", ")", "=", "?", "¿", "'", "á", "é", "í", "ó", "ú", "ñ", "Ñ","©","@","®","-","html");
$nombre_url = str_replace($caracteresespeciales,"_",$url);
$conexion=mysql_connect($host,$usuario_db,$pass_usuario_db);
$seldb=mysql_select_db($basedatos);
//Hago la consulta
$sop = "SELECT * FROM noticias WHERE url='$nombre_url'";
//Guardo el resultado
$result = mysql_query($sop);
while ($lista = mysql_fetch_array($result)){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=$lista["titulo"];?></title>
</head>
<body>
<?=$lista["titulo"];?>
</body>
</html>
<?
}
mysql_close($conexion);
?>
y el .htaccess
Código:
# .htaccess file
Options FollowSymLinks
#activacion del motor de escritura
RewriteEngine On
#aca van las reglas de reescritura
RewriteRule ^(.*)-(.*).html$ noticia.php?url=$2