Este fórum é para dúvidas onde a base da questão é a linguagem PHP.
Moderador: web
por SoulBurst Offline » Ter Fev 07, 2012 12:27 am
|
Olá amigos boa noite.
É o seguinte já tentei de tudo mas não consigo meter url amigaveis já tentei de tudo (até mesmo com o gerenciador do forum) e não consigo.
Então no meu site tem o seguinte url:
http://www.dominio.com/index.php?page=fam&id=1
fam é um ficheiro PHP que pega os artigos do mysql cuja familia tem o ID "1"
Dentro da página index.php tenho o seguinte código:
- Código: Selecionar todos
<div class="conteudo"> <? $page = addslashes(htmlentities($_GET['page'])); if((eregi('http|www|https|ftp', $page)) || (!file_exists($page . ".php")) && (!empty($page))) { echo "<div align=\"center\" class=\"style6\">Pagina nao encontrada!</div>"; }elseif(empty($page)) { include("home.php"); }else{ include($page . ".php"); } ?> </div>
Quero que fique algo do género:
http://www.dominio.com/index/fam/1 ou http://www.dominio.com/fam/1
Tem como? Estou a horas em volta disso não consigo... Já mudei vezes sem conta o .htaccess mas penso que o problema está no código que tenho no index.php
Desde já grato pela vossa ajuda e também pelo excelente forum.

SoulBurst
NOVO MEMBRO
Mensagens: 4
Registrado em: Seg Fev 06, 2012 11:39 pm
|
por web Online » Ter Fev 07, 2012 8:48 am
Tenta o seguinte:
- Código: Selecionar todos
RewriteEngine on
RewriteRule ^([a-z,0-9,A-Z,_-]+)\/([a-z,0-9,A-Z,_-]+)$ /index.php?page=$1&id=$2
Essa regra é válida para: /fam/1
irá passar os valores respectivamente, $1 e $2

Gostou do que encontrou? Divulgue, indique, participe, agradeça pelas respostas.
Faço scripts personalizados ou reparos em scripts. Orçamento MSN codigosnaweb1 [@] gmail [.] com
web
ADMIN
Mensagens: 12457
Registrado em: Sáb Jan 20, 2007 6:08 pm
Localização: RJ / RJ / Brasil
|
por SoulBurst Offline » Qua Fev 08, 2012 6:54 am
Muito obrigado pela ajuda funcionou. Mas estou a ter problemas com o design da página, mesmo chamando os ficheiros CSS do style não fica igual. Porque a minha página também usa flash e no caso da página index.php a div conteudo é dinâmico. Ou seja para ter tudo a funcionar normalmente irei ter que voltar a editar tudo nas páginas?

SoulBurst
NOVO MEMBRO
Mensagens: 4
Registrado em: Seg Fev 06, 2012 11:39 pm
|
por SoulBurst Offline » Qua Fev 08, 2012 7:38 am
No caso o código que eu tenho é o que está em baixo. Se eu usar url amigavel a página perde a imagem em flash e o estilo dinâmico, perde o dinamismo tb quando uso o index.php?page= O código não foi feito para isso. E também não sei alterar não percebo nada de js 
- Código: Selecionar todos
jQuery.noConflict();
jQuery(document).ready(function(){ hideContent = function(contentString){ jQuery("div.dynamicContent").fadeOut( 1000 ,function() { showContent(contentString);playSound(0); }); }; showContent = function (contentString) { jQuery.ajax({ type: "GET", url: contentString, dataType:"html", success: function(data){ jQuery("div.dynamicContent").html(data); jQuery("div.dynamicContent").slideDown(1500); }, error: function () { alert("Page "+contentString+" not found"); } }); };
if(jQuery(document).getUrlParam("page")!=null) { hideContent(jQuery(document).getUrlParam("page")); } else { showContent("home.php"); } });
function sendToASUnselectButton(button_id) { thisMovie(button_id).sendToASUnselectButton(""); } function thisMovie(movieName) { if (navigator.appName.indexOf("Microsoft") != -1) { return window[movieName]; } else { return document[movieName]; } }
var requiredMajorVersion = 9; var requiredMinorVersion = 9; var requiredRevision = 0; var selected_button =""; var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; var online = ( ((window.location+'').substring(0,4)).toLowerCase()=='http' ) ? true : false;
function myButton (buttonText,buttonLink) { if (!online && !isIE) { document.write(' <DIV ID="flashMovie'+(anim_ids+1)+'" STYLE="width: 200; height: 31; z-index: 100;" onClick="showPage(\''+buttonLink+'\','+anim_ids+1+')">'); } AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','width','200','height','31','src','flash/button','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','flash/button','flashvars','custom_xml_url=button.xml&item_text='+buttonText+'&item_url='+buttonLink+'&button_id='+(anim_ids+1)+'&isIE='+isIE,'scale','noScale','wmode','transparent'); if (!online && !isIE) { document.write('</DIV>'); } }
function myHeader () { AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','width','658','height','150','src','flash/header','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','flash/header','flashvars','custom_xml_url=custom.xml', 'bgcolor','#FFFFFF','scale','noScale'); //end AC code }
function myFlashHeader (_src,_width,_height,_bgcolor,_divID,_xml) { if (window.document.getElementById(_divID)) { window.document.getElementById(_divID).innerHTML=AC_FL_RunContentDiv( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','width',_width,'height',_height,'src',_src,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie',_src,'flashvars','custom_xml_url='+_xml, 'bgcolor',_bgcolor,'allowScriptAccess','sameDomain','scale','noScale'); //end AC code } else { alert("Div '"+_divID+"' not found "); } }
function myHeader () { //AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','width','540','height','150','src','flash/header','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','flash/header','flashvars','custom_xml_url=custom.xml', 'bgcolor','#FFFFFF','scale','noScale'); //end AC code AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','width','902','height','351','src','flash/header','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','flash/header','flashvars','custom_xml_url=custom.xml', 'bgcolor','#FFFFFF','scale','noScale'); //end AC code }
function myFlashGallery (_src,_width,_height,_bgcolor,_divID) { if (window.document.getElementById(_divID)) { window.document.getElementById(_divID).innerHTML=AC_FL_RunContentDiv( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0','width',_width,'height',_height,'src',_src,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie',_src,'bgcolor',_bgcolor,'allowScriptAccess','sameDomain','allowFullScreen','true'); //end AC code AC_FL_RunContentDiv( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0','width','540','height','418','src','flash/gallery/gallery','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','flash/gallery/gallery','bgcolor','#FFFFFF','allowFullScreen','true'); //end AC code } else { alert("Div '"+_divID+"' not found "); } }
function showPage(pageURL,button_id) { hideContent(pageURL); if (selected_button!="" && button_id!=selected_button) { sendToASUnselectButton('anim_'+selected_button); } if (button_id!=undefined) {selected_button = button_id;} }
/* Copyright (c) 2006-2007 Mathias Bank (http://www.mathias-bank.de) * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. * * Version 2.1 * * Thanks to * Hinnerk Ruemenapf - http://hinnerk.ruemenapf.de/ for bug reporting and fixing. * Tom Leonard for some improvements * */ jQuery.fn.extend({ /** * Returns get parameters. * * If the desired param does not exist, null will be returned * * To get the document params: * @example value = $(document).getUrlParam("paramName"); * * To get the params of a html-attribut (uses src attribute) * @example value = $('#imgLink').getUrlParam("paramName"); */ getUrlParam: function(strParamName){ strParamName = escape(unescape(strParamName)); var returnVal = new Array(); var qString = null; if (jQuery(this).attr("nodeName")=="#document") { //document-handler if (window.location.search.search(strParamName) > -1 ){ qString = window.location.search.substr(1,window.location.search.length).split("&"); } } else if (jQuery(this).attr("src")!="undefined") { var strHref = jQuery(this).attr("src") if ( strHref.indexOf("?") > -1 ){ var strQueryString = strHref.substr(strHref.indexOf("?")+1); qString = strQueryString.split("&"); } } else if (jQuery(this).attr("href")!="undefined") { var strHref = jQuery(this).attr("href") if ( strHref.indexOf("?") > -1 ){ var strQueryString = strHref.substr(strHref.indexOf("?")+1); qString = strQueryString.split("&"); } } else { return null; } if (qString==null) return null; for (var i=0;i<qString.length; i++){ if (escape(unescape(qString[i].split("=")[0])) == strParamName){ returnVal.push(qString[i].split("=")[1]); } } if (returnVal.length==0) return null; else if (returnVal.length==1) return returnVal[0]; else return returnVal; } });

SoulBurst
NOVO MEMBRO
Mensagens: 4
Registrado em: Seg Fev 06, 2012 11:39 pm
|
por web Online » Qua Fev 08, 2012 9:02 am
Você pode usar o base href, para definir o diretório padrão dos arquivos usados no documento.

Gostou do que encontrou? Divulgue, indique, participe, agradeça pelas respostas.
Faço scripts personalizados ou reparos em scripts. Orçamento MSN codigosnaweb1 [@] gmail [.] com
web
ADMIN
Mensagens: 12457
Registrado em: Sáb Jan 20, 2007 6:08 pm
Localização: RJ / RJ / Brasil
|
por SoulBurst Offline » Qua Fev 08, 2012 3:20 pm
Penso que é disto que estás a falar certo? http://imasters.com.br/artigo/7372/webstandards/urls_amigaveis_path_para_imagens_scripts_e_css/
Mas mesmo assim não resolve o problema, porque isso é quanto ao css. Essa parte eu já entendi e muito obrigado pela ajuda. Mas o problema penso que está naquele ficheiro de javascript.
É o seguinte, fiz o que disses-te lá em cima editei o htaccess e funcionou direitinho tudo, excepto a parte do css que eu resolvi, e agora melhor ainda depois de ter visto o artigo da imasters, porém a parte que diz respeito ao conteúdo dinâmico aí é que está o problema. O ficheiro js funciona direito quando o url está da seguinte forma:
www.meudominio.com/fam.php (ele reconhece o index como base)
mas quando fica
www.meudominio.com/?page=fam&id=1 OU www.meudominio.com/index?page=fam&id=1
aí estraga :/ ou seja mesmo editando a parte htaccess e ficando www.meudominio.com/fam/1 o código js reconhece como index.php?page=fam&id=1 e não faz o que devia fazer.
Tem alguma forma de contornar isso?
Mais uma vez obrigado pela ajuda Web.

SoulBurst
NOVO MEMBRO
Mensagens: 4
Registrado em: Seg Fev 06, 2012 11:39 pm
|
por web Online » Qua Fev 08, 2012 5:25 pm
Já tentou definir o caminho direto para o arquivo incluíndo seu domínio? Ao invés de usar só index.php?... você irá usar o caminho completo: http://....index.php?....

Gostou do que encontrou? Divulgue, indique, participe, agradeça pelas respostas.
Faço scripts personalizados ou reparos em scripts. Orçamento MSN codigosnaweb1 [@] gmail [.] com
web
ADMIN
Mensagens: 12457
Registrado em: Sáb Jan 20, 2007 6:08 pm
Localização: RJ / RJ / Brasil
|
Voltar para PHP
Quem está online
Usuários navegando neste fórum: Nenhum usuário registrado e 4 visitantes
|
|
|