Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/09/2012, 07:00
Avatar de Ex_shadow
Ex_shadow
 
Fecha de Ingreso: febrero-2012
Ubicación: Calera Avellaneda, Buenos Aires, Argentina, Argentina
Mensajes: 95
Antigüedad: 12 años, 2 meses
Puntos: 4
Pregunta htacces y urls amigables php

Hola buenas! tengo un problema con "mi" htaccess

Estaba buscando como crear permalinks o urls amigables (creo que es lo mismo) para una seccion para un cliente, el inconveniente es el siguiente:

La url original es esta:

http://localhost/Ciegos/Shows ( tengo el htaccess para ocultar las extenciones)

y con get (aca esta el problema)

http://localhost/Ciegos/Shows?Pag=2 (Tengo un paginador en caso de existir Pag)

Antes de comentar el inconveniente pongo el script
Código Apache:
Ver original
  1. RewriteEngine On
  2. RewriteCond %{REQUEST_FILENAME} !-d
  3. RewriteCond %{REQUEST_FILENAME}\.php -f
  4. RewriteRule ^(.*)$ $1.php
  5. RewriteCond %{REQUEST_FILENAME} !-d
  6. RewriteCond %{REQUEST_FILENAME}\.html -f
  7. RewriteRule ^(.*)$ $1.html
  8.  
  9. <IfModule mod_rewrite.c>
  10. RewriteEngine On
  11. RewriteBase /Ciegos/Shows/
  12. RewriteCond %{REQUEST_FILENAME} !-f
  13. RewriteCond %{REQUEST_FILENAME} !-d
  14. RewriteRule . /Ciegos/Shows.php [L]
  15. </IfModule>

(Debo de comentar que busque, y lei articulos sobre htaccess y no lo entiendo :S)

El problema esta en que Si entro a:

http://localhost/Ciegos/Shows/Gira-2012-en-san-bernardo

Ingresa perfecto (Seria la informacioon detallada del show)

Pero si entro a http://localhost/Ciegos/Shows/Pag/2
Que seria la ubicacion del paginador muestra lo que seria:
http://localhost/Ciegos/Shows/


El script php

Código PHP:
Ver original
  1. <?
  2.     # --- php ini
  3.     include("ini.php");
  4.  
  5.     # --- URL base de la aplicacion
  6.     $base = "http://localhost/Ciegos/";
  7.      
  8.     # --- Si es un permalink
  9.     if(!(("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])==$base) && !(basename($_SERVER['REQUEST_URI']) == "Shows")){
  10.      
  11.         # --- Obtener el slug
  12.         $slug = basename($_SERVER['REQUEST_URI']);
  13.        
  14.         # --- Consulta mysql
  15.         $Consulta = $Mysql->Consulta("SELECT * FROM noticias WHERE permalink='".$slug."' LIMIT 1");
  16.        
  17.         # --- Associando variable
  18.         $Campo = $Mysql->Assoc($Consulta);
  19.    
  20.         echo '<div id="Noticia">';
  21.             echo '<h1>'.$Campo['titulo'].'</h1><time><img src="http://'.$_SERVER['HTTP_HOST'].'/Ciegos/Imagenes/Iconos/clock32.png" /> <span>'.$Campo['tiempo'].'</span> </time>';
  22.             echo '<img src="http://'.$_SERVER['HTTP_HOST'].'/Ciegos/Content/Noticias/'.$Campo['flyer'].'" class="Original"/>';
  23.             echo '<p>'.$Campo['informacion'].'</p>';
  24.            
  25.             echo '
  26.             <div class="Social">
  27.                         <iframe src="http://www.facebook.com/plugins/like.php?href=http://laentreviasrock.com/Shows/'.$Campo['permalink'].'&amp;send=false&amp;layout=button_count&amp;width=125&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=lucida+grande&amp;height=20" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:125px; height:20px;" allowTransparency="true"></iframe>
  28.                        
  29.                         <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://'.$_SERVER["HTTP_HOST"].'/Shows/'.$Campo['permalink'].'" data-lang="es">Twittear</a>
  30.                         <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
  31.    
  32.                         <!-- Inserta esta etiqueta donde quieras que aparezca Botón +1. -->
  33.                         <div class="g-plusone" data-annotation="none" data-href="http://'.$_SERVER["HTTP_HOST"].'/Shows/'.$Campo['permalink'].'"></div>
  34.                        
  35.                         <!-- Inserta esta etiqueta después de la última etiqueta de Botón +1. -->
  36.                         <script type="text/javascript">
  37.                           window.___gcfg = {lang: "es"};
  38.                        
  39.                           (function() {
  40.                             var po = document.createElement("script"); po.type = "text/javascript"; po.async = true;
  41.                             po.src = "https://apis.google.com/js/plusone.js";
  42.                             var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(po, s);
  43.                           })();
  44.                         </script>
  45.                        
  46.                     </div>
  47.             ';
  48.            
  49.         echo '</div>';
  50.        
  51.     }
  52.     if(basename($_SERVER['REQUEST_URI'])=="Shows" || isset($_GET['Pag'])){
  53.        
  54.         # --- Paginacion
  55.         # --- Configuracion
  56.         $Consult = 'SELECT * FROM noticias ORDER BY id DESC';
  57.         $Reg = 5;
  58.         $Botones = 5;
  59.         $Class = 'Paginas';
  60.    
  61.    
  62.        
  63.         # - Posicion
  64.         if(!isset($_GET['Pag']) || $_GET['Pag']<0){ // Si no Existe Pag o Es menor a 0
  65.             $Pagina = 1;
  66.         }else{
  67.             $Pagina = $Seguridad->Numero($_GET['Pag']);
  68.         }
  69.        
  70.         # - Opciones
  71.         $Consulta = $Mysql->Consulta($Consult); // - Consulta que devolvera los datos
  72.         $Registros = $Reg; // - Registros a mostrar
  73.         $Intervalo = $Botones; // - Intervalo entre botones
  74.        
  75.         # - Configuracion
  76.         $Cantidad = $Mysql->Reg_Num($Consulta); // - Cantidad de registros
  77.         $Desde = ($Pagina-1)*$Registros; // - Desde que registro empieza la busqueda
  78.         $Total = ceil($Cantidad/$Registros); // - Total divicion de registros y total a mostrar redondeado
  79.         $Botones = ($Intervalo*2)+1; // - Bonotes que se mostraran
  80.         $i = 0; // - Necesario para los bucle for
  81.         $Func = $Pagina-$Intervalo; // - Paginas en total
  82.         $Consults = $Mysql -> Consulta($Consult.' LIMIT '.$Desde.' , '.$Registros); // - Consulta a bd con limite de reg
  83.            
  84.         # - Navegacion
  85.         $Anterior = $Pagina-1;
  86.         $Siguiente = $Pagina+1;
  87.        
  88.         echo '<div id="Noticias">';
  89.        
  90.         # - Bucle
  91.         while($Campo = $Mysql -> Assoc($Consults)){
  92.                            
  93.                 # --- Noticias
  94.                 echo '
  95.                
  96.                
  97.                
  98.                 <div class="Noticia">
  99.                
  100.                     <h1>'.$Convert->Mayusculas($Campo['titulo']).'</h1> <time><img src="http://'.$_SERVER['HTTP_HOST'].'/Ciegos/Imagenes/Iconos/clock32.png" /> <span>'.$Campo['tiempo'].'</span> </time>
  101.                    
  102.                     <i><img src="Content/Noticias/'.$Campo['flyer'].'" class="Flyer" /></i>
  103.                    
  104.                     <p>'.$Convert->Mayusculas($Campo['informacion']).'</p> <a href="http://'.$_SERVER['HTTP_HOST'].'/Ciegos/Shows/'.$Campo['permalink'].'">[+info]</a>
  105.                
  106.                     <div class="Social">
  107.                         <iframe src="http://www.facebook.com/plugins/like.php?href=http://laentreviasrock.com/Shows/'.$Campo['permalink'].'&amp;send=false&amp;layout=button_count&amp;width=125&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=lucida+grande&amp;height=20" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:125px; height:20px;" allowTransparency="true"></iframe>
  108.                        
  109.                         <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://'.$_SERVER["HTTP_HOST"].'/Shows/'.$Campo['permalink'].'" data-lang="es">Twittear</a>
  110.                         <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
  111.    
  112.                         <!-- Inserta esta etiqueta donde quieras que aparezca Botón +1. -->
  113.                         <div class="g-plusone" data-annotation="none" data-href="http://'.$_SERVER["HTTP_HOST"].'/Shows/'.$Campo['permalink'].'"></div>
  114.                        
  115.                         <!-- Inserta esta etiqueta después de la última etiqueta de Botón +1. -->
  116.                         <script type="text/javascript">
  117.                           window.___gcfg = {lang: "es"};
  118.                        
  119.                           (function() {
  120.                             var po = document.createElement("script"); po.type = "text/javascript"; po.async = true;
  121.                             po.src = "https://apis.google.com/js/plusone.js";
  122.                             var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(po, s);
  123.                           })();
  124.                         </script>
  125.                        
  126.                     </div>
  127.                    
  128.                 </div>';
  129.                    
  130.         }
  131.        
  132.         # -- Empieza la Navegacion
  133.         echo '<div class="Paginacion">';
  134.        
  135.         if($Total>1){
  136.         # - Boton Anterior
  137.         if($Pagina>1){
  138.             echo '<a href="?Pag='.$Anterior.'"><</a>';
  139.         }
  140.        
  141.         # - Paginas
  142.         while ($i<$Botones) {
  143.          
  144.             if ($Func>0 and $Func<=$Total) {
  145.        
  146.                 if($Func == $Pagina){
  147.                     echo '<a class="Disabled">'.$Func.'</a>';
  148.                 }else{
  149.                   echo '<a href="?Pag='.$Func.'" class="'.$Class.'">'.$Func.'</a>';
  150.                 }
  151.              $i++;
  152.             }
  153.        
  154.                 if($Func>$Total){
  155.                     $i=$Botones;
  156.                 }
  157.              $Func++;
  158.             }
  159.        
  160.         /* Simple
  161.         echo $Pagina.' / '.$Total;*/
  162.        
  163.         # - Boton Siguiente
  164.         if($Pagina>=1 and $Pagina<$Total || !isset($_GET['Pag'])){
  165.             echo '<a href="?Pag='.$Siguiente.'">></a></div>';
  166.         }else{ echo '</div>'; }
  167.         }else{
  168.             echo '<div id="Aviso">'.$Mensaje.'</div></div>';
  169.         }
  170.  
  171.         echo '</div>';
  172.        
  173.     }
  174. ?>