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.
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.
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á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


0