PHP - Problema con .htaccess y redirecciones (modificar código PHP)

 
Vista:

Problema con .htaccess y redirecciones (modificar código PHP)

Publicado por Daniel (3 intervenciones) el 03/05/2011 13:25:22
Buenas, pues he decidido entrar a algún foro de programadores para haber si me podeís echar una mano.

Estoy trabajando actualmente con un script ya programado, ahora, he conseguido hacer redirecciones del tipo (cat-IDNUMERO.html) con éxito.

Pero, no es el tipo de redireccion que busco.
Busco una redireccion tipo: (/NOMBRECAT/SUBCATEGORIA)

Tengo el .htaccess configurado para que lea números y letras.
Me interesaría saber que es lo que debo modificar, puesto que he intentado cambiar variables que contienen el "id" por "name" que sería en texto pero no consigo redireccionar.

Os dejo código y así haber si me podeís echar una mano.
Gracias.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
require_once("config.php");
require_once("include.php");
require_once("template_index.php");
header("Content-Type: text/html; charset=utf-8");
 
$c *= 1;
if ($c == 0) $c = 1;
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password);
mysql_select_db($mysql_database, $bd);
$sql = mysql_query("SELECT name, title, description, pages, ref FROM {$prefix}categories WHERE id = $c");
$current_category = array_map("parse_output",mysql_fetch_array($sql, MYSQL_ASSOC));
if (($c > 1) & !$current_category["name"]){
	mysql_close();
	header("Location: {$dir}");
	exit();
};
if (!$current_category["name"]) $current_category["name"] = "Mi Sitio F&aacute;cil - Directorio Web";
if (!$current_category["description"]) $current_category["description"] = $current_category["name"]." ".$current_category["title"];
$replace = array("[CATEGORY_NAME]" => $current_category["name"], "[CATEGORY_TITLE]" => $current_category["title"], "[CATEGORY_DESCRIPTION]" => $current_category["description"]);
echo strtr($TEMPLATE["HEADING"],$replace);
flush();
$last_category = false;
$ref = $c;
while(!$last_category){
	$n_parent_categories += 1;
	$sql = mysql_query("SELECT id, name, ref FROM {$prefix}categories WHERE id = $ref");
	$parent_categories[$n_parent_categories-1] = array_map("parse_output",mysql_fetch_array($sql, MYSQL_ASSOC));
	if ($parent_categories[$n_parent_categories-1]["ref"] == 0){
		$last_category = true;
	}else{
		$ref = $parent_categories[$n_parent_categories-1]["ref"];
	};
};
echo $TEMPLATE["PATH"]["HEADING"];
for ($x = $n_parent_categories-1; $x >= 0; $x--){
	if ($x != $n_parent_categories-1) echo $TEMPLATE["PATH"]["SEPARATOR"];
	if ($x == 0){
		$replace = array("[CATEGORY_NAME]" => $parent_categories[$x]["name"]);
		echo strtr($TEMPLATE["PATH"]["CURRENT_CATEGORY"],$replace);
	}else{
		if ($parent_categories[$x]["id"] > 1){
			$category_url = $dir.'cat-'.$parent_categories[$x]["id"].'.html';
		}else{
			$category_url = $dir;
		};
		$replace = array("[CATEGORY_NAME]" => $parent_categories[$x]["name"], "[CATEGORY_URL]" => $category_url);
		echo strtr($TEMPLATE["PATH"]["CATEGORY"],$replace);
	};
};
echo $TEMPLATE["PATH"]["FOOTER"];
flush();
$sql = mysql_query("SELECT id, name FROM {$prefix}categories WHERE ref = $c ORDER BY name");
$n_subcategories = mysql_num_rows($sql);
for ($x = 0; $x < $n_subcategories; $x++){
	$subcategories[$x] = array_map("parse_output",mysql_fetch_array($sql, MYSQL_ASSOC));
};
if ($n_subcategories > 0){
	$replace = array("[NUMBER_CATEGORIES]" => $n_subcategories, "[CATEGORY_NAME]" => $current_category["name"]);
	echo strtr($TEMPLATE["SUBCATEGORIES"]["HEADING"],$replace);
	echo $TEMPLATE["SUBCATEGORIES"]["BEFORE_COLUMNS"];
	for ($x = 0; $x < ceil($n_subcategories/2); $x++){
		$replace = array("[CATEGORY_NAME]" => $subcategories[$x]["name"], "[CATEGORY_URL]" => $dir.'cat-'.$subcategories[$x]["id"].'.html');
		echo strtr($TEMPLATE["SUBCATEGORIES"]["CATEGORY"],$replace);
	};
	echo $TEMPLATE["SUBCATEGORIES"]["BETWEEN_COLUMNS"];
	for ($x = ceil($n_subcategories/2); $x < $n_subcategories; $x++){
		$replace = array("[CATEGORY_NAME]" => $subcategories[$x]["name"], "[CATEGORY_URL]" => $dir.'cat-'.$subcategories[$x]["id"].'.html');
		echo strtr($TEMPLATE["SUBCATEGORIES"]["CATEGORY"],$replace);
	};
	echo $TEMPLATE["SUBCATEGORIES"]["AFTER_COLUMNS"];
	echo $TEMPLATE["SUBCATEGORIES"]["FOOTER"];
}else{
	$replace = array("[CATEGORY_NAME]" => $current_category["name"]);
	echo strtr($TEMPLATE["SUBCATEGORIES"]["NO_CATEGORIES"],$replace);
};
if ($current_category["pages"] == "y"){
	$replace = array("[CATEGORY_NAME]" => $current_category["name"], "[SUBMISSION_URL]" => $dir.'nuevoenlace-'.$c.'.html');
	echo strtr($TEMPLATE["SUBMISSION_LINK"],$replace);
	flush();
	if ($s == 0) $s = 1;
	$n = 10;
	$sql = mysql_query("SELECT COUNT(*) AS total_pages FROM {$prefix}pages WHERE category = $c AND accepted = 'y'");
	$total_pages = mysql_result($sql,0,"total_pages");
	if ($total_pages > 0){
		$sql = mysql_query("SELECT id, url, title, description FROM {$prefix}pages WHERE category = $c AND accepted = 'y' ORDER BY title LIMIT ".($s-1).",$n");
		$n_pages = mysql_num_rows($sql);
		for ($x = 0; $x < $n_pages; $x++){
			$pages[$x] = array_map("parse_output",mysql_fetch_array($sql, MYSQL_ASSOC));
		};
	};
	$e = min($s + $n - 1, $s + $n_pages - 1);
	if ($n_pages > 0){
		$replace = array("[STARTING_PAGE_NUMBER]" => $s, "[ENDING_PAGE_NUMBER]" => $e, "[TOTAL_PAGES]" => $total_pages, "[CATEGORY_NAME]" => $current_category["name"]);
		echo strtr($TEMPLATE["PAGES"]["HEADING"],$replace);
		for ($x = 0; $x < $n_pages; $x++){
			if ($pages[$x]["domain"]){
				$replace = array("[PAGE_NUMBER]" => $x, "[PAGE_TITLE]" => $pages[$x]["title"], "[PAGE_DESCRIPTION]" => $pages[$x]["description"], "[PAGE_URL]" => $pages[$x]["url"], "[PAGE_DOMAIN]" => $pages[$x]["domain"]);
				echo strtr($TEMPLATE["PAGES"]["FEED_PAGE"],$replace);
			}else{
				$replace = array("[PAGE_NUMBER]" => $x, "[PAGE_TITLE]" => $pages[$x]["title"], "[PAGE_DESCRIPTION]" => $pages[$x]["description"], "[PAGE_URL]" => $pages[$x]["url"], "[PAGE_DOMAIN]" => $pages[$x]["domain"]);
				echo strtr($TEMPLATE["PAGES"]["PAGE"],$replace);
			};
		};
		if ($s != 1 || $e != $total_pages){
			function pagination($s){
				global $c, $dir;
				if ($c != 1) { $query = "cat-$c"; };
				if (($c != 1) & $s != 1){
					$query .= "&s=$s";
				}elseif ($s != 1){
					$query = "index.php?s=$s";
				};
				return $dir.$query;
			};
			echo $TEMPLATE["PAGES"]["PAGINATION"]["HEADING"];
			if ($s != 1){
				$previous = $s - $n;
				$replace = array("[PAGINATION_URL]" => pagination($previous));
				echo strtr($TEMPLATE["PAGES"]["PAGINATION"]["PREVIOUS"],$replace);
			};
			for ($x = 1; $x <= ceil($total_pages/$n); $x++){
				$current = ($x-1) * $n + 1;
				if ($current == $s){
					$replace = array("[PAGINATION_NUMBER]" => $x);
					echo strtr($TEMPLATE["PAGES"]["PAGINATION"]["CURRENT_NUMBER"],$replace);
				}else{
					$replace = array("[PAGINATION_NUMBER]" => $x, "[PAGINATION_URL]" => pagination($current));
					echo strtr($TEMPLATE["PAGES"]["PAGINATION"]["NUMBER"],$replace);
				};
			};
			if ($e < $total_pages){
				$next = $s + $n;
				$replace = array("[PAGINATION_URL]" => pagination($next));
				echo strtr($TEMPLATE["PAGES"]["PAGINATION"]["NEXT"],$replace);
			};
			echo $TEMPLATE["PAGES"]["PAGINATION"]["FOOTER"];
		};
		echo $TEMPLATE["PAGES"]["FOOTER"];
	}else{
		$replace = array("[CATEGORY_NAME]" => $current_category["name"]);
		echo strtr($TEMPLATE["PAGES"]["NO_PAGES"],$replace);
	};
};
?>


PD: También estaría interesado en que las categorías solo salieran con minusculas, sin espacios y sin acentos. Actualmente en la base de datos tiene espacios, mayúsculas y acentos.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Problema con .htaccess y redirecciones (modificar código PHP)

Publicado por xve (6935 intervenciones) el 03/05/2011 15:58:00
Hola Daniel, me puedes indicar cuales son los campos que quieres que tenga el mod_rewrite... para esta estructura /NOMBRECAT/SUBCATEGORIA
Que campo seria para NOMBRECAT y cual para SUBCATEGORIA

Nos puedes mostrar el fichero .htaccess?

Un saludo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Problema con .htaccess y redirecciones (modificar código PHP)

Publicado por Daniel (3 intervenciones) el 03/05/2011 23:15:42
Haber, NOMBRECAT = columna: id (de la bd) 17 = columna: name (de la bd) Cine. Esto por ejemplo.
Y SUBCATEGORIA Seria asi: Cine-17/Peliculas-200

Todas las categorías están en una misma tabla.

He visitado otro sitio de internet con el mismo script que el que estoy utilizando actualmente y lo tiene como yo deseo, excepto una parte, la de renombrar caracteres con acentos y demas, y las mayuscúlas convertirlas en minuscúlas. (no he conseguido que conteste el autor del sitio, por eso he recurrido a ayuda de algun programador con estos conocimientos)

En cuestión el sitio del que hablo deja las url's de esta forma: /Creencias-24/Religion-83/

Aquí está mi .htaccess:

1
2
3
4
5
6
7
8
9
10
11
12
13
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
 
#RewriteRule ^categoria-([_0-9a-z-]+)/?$ index.php?c=$1 [L] //SE USA LA SIGUIENTE REGLA ESTA NO.
RewriteRule ^cat-([_0-9A-Za-z-]+).html/?$ index.php?c=$1 [L]
RewriteRule ^nuevoenlace-([0-9]+).html/?$ enlace.php?c=$1 [L]
RewriteRule ^buscar-([_0-9a-z-]+).html/?$ buscar.php?q=$1 [L]
RewriteRule ^pagina-([0-9]+).html/?$ index.php?s=$1 [L]
 
#redirecciona de sin 3w a con 3w
RewriteCond %{HTTP_HOST} !^www\.***\.es [NC]
RewriteRule ^(.*)$ http://www.***.es/$1 [r=301,L]
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Problema con .htaccess y redirecciones (modificar código PHP)

Publicado por Daniel (1 intervención) el 05/05/2011 23:59:05
No he conseguido realizar las modificaciones aún. Espero ayuda de algún experto, muchas gracias.
Daniel
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Problema con .htaccess y redirecciones (modificar código PHP)

Publicado por Daniel (3 intervenciones) el 09/05/2011 14:43:49
Esto es lo que quiero hacer exactamente:

http://www.jikop.com/
http://www.muchos.org/

Hay está tal y como lo quisiera.
Espero ayuda.

Gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar