Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

gremio10

[Resolvido] Erro url amigavel

Recommended Posts

Pessoal,seguinte, fiz o codigo da url assim:

 

RewriteEngine On

RewriteRule ^(.+)/$ index.php?pg=$1
RewriteRule ^(.+)/(.+)$ index.php?pg=$1&id=$2

 

Funcionar funciona direitinho, o problema ficou no css...

 

as imgs que utilizo pelo css não estão mais aparecendo, parece que eles caem na minha segunda regra, como posso fazer para que eles não caiam ?

 

Obrigado

Compartilhar este post


Link para o post
Compartilhar em outros sites

não use tantos coringas... acredito que se você não sobrescrever o ponto, não terá problemas com o css

Compartilhar este post


Link para o post
Compartilhar em outros sites

se eu nao me engano esse topico foi duplicado por que ja te dei solução no outro topico por tanto nao respondam neste

Compartilhar este post


Link para o post
Compartilhar em outros sites

brother nao to estragando eu posso ajudar sim

posta o codigo

Uma pergunta o CSS ta funcionando?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ta sim cara.

 

estilos.css

 

*{font:12px Verdana, Geneva, sans-serif; color:#222; text-decoration:none; list-style:none;}
body{margin:0; padding:0px;}
a:hover{text-decoration:underline}
#logomarca span {display:none;}
#logomarca h1 {margin:15px; background:url(images/logomarca.png) no-repeat; width:350px; height:80px;}
#menu{background:url(images/bd_menu.png) repeat-x; height:30px; width:100%;}
#menu ul{margin:0; padding:0; margin-left:20px;}
#menu li {float:left; margin-top:6px;}
#menu li a {color:#333; padding:4px 16px; padding-bottom:8px;}
#menu li a:hover {background:url(images/bd_menu_btn.png) repeat-x; text-decoration:none; color:#eee; height:30px; border-radius:3px;}
#buscar {margin-left:460px; margin-bottom:100px; margin-top:-100px; height:30px; width:400px;}
#buscar #busca {background:url(images/busca.png) no-repeat; width:260px; height:30px; border:none; margin:0; text-indent:5px; color:#999;}
#buscar #btn{background:url(images/btn.png) no-repeat; width:40px; height:30px; margin-bottom:3px; margin-left:-4px; border:none; cursor:pointer;}
#rodape{height:100px; width:100%; background:#000; float:left; margin-top:10px;}

/** First **/
#produtos{margin:0 auto;}
ul#product{float:left;}
ul#product li{float:left; width:240px; height:340px; border:1px solid #EEE; background-color:#EEE; margin:3px; border-radius: 3px;}
ul#product li .name{padding:5px; font-weight:bold;}
ul#product li #description-detail{height:50px; padding:5px; text-align:center;}
ul#product li #price{height:40px; padding:5px; font-size:15px; text-align:center;}
ul#product li #price .price-promotion, ul#product li #price .price-promotion s{color:#F00}
ul#product li #price .price-promotion s{text-decoration:line-through;}
ul#product li #price .or, ul#product li #price .or b{font-size:11px;}
ul#product li #price .or b{color:#F00;}

/** Detail **/
#box-comprar-top{float:right; margin-top:-20px;}
#box-comprar-top h2{float:left; color:#333; margin:5px;}
#box-comprar-top form {float:left;}
#box-comprar-bottom {float:right; margin:6px 0 0 10px; clear:both;}
#box-comprar-bottom h2{float:left; color:#333; margin:5px;}
#box-comprar-bottom form {float:left;}
#geral-desc{margin:15px;}
#geral-desc img{float:left; clear:both; border:1px solid #444;}
#geral-desc #name h1{float:left; font-size:20px; font-weight:bold; margin:10px; width:600px; height:60px;}
#geral-desc #precos_desc{float:left; height:50px; margin:10px; font-size:15px; width:300px;}
#geral-desc #precos_desc .price-promotion, #geral-desc #precos_desc .price-promotion s{color:#F00;}
#geral-desc #precos_desc .price-promotion s{text-decoration:line-through;}
#geral-desc #precos_desc .or, #geral-desc #precos_desc .or b{font-size:11px;}
#geral-desc #precos_desc .or b{color:#F00}
#geral-desc #social{float:right; width:300px; height:10px; margin-top:-10px;}
#geral-desc #social #rede_social{float:left; margin:5px;}
#geral-desc #delivery{float:left; width:650px; height:30px; display:inline; margin:10px;} 
#geral-desc #delivery h1{font-weight:bold; float:left; margin:0; padding:0;}
#geral-desc #descricao{float:left; width:685px; margin:15px 10px;}

/** Produtos Relacionados **/
#product-related b{float:left; padding:10px; clear:both; font-weight:bold;}
ul#related{clear:both;}
ul#related li{float:left; margin:5px; border:1px solid #EEE; border-radius:3px; background-color:#EEE; height:340px; width:240px;}
ul#related li .name{padding:5px; font-weight:bold;}
ul#related li #description-detail{height:50px; padding:5px; text-align:center;}
ul#related li #price{height:40px; padding:5px; font-size:15px; text-align:center;}
ul#related li #price .price-promotion, ul#product li #price .price-promotion s{color:#F00}
ul#related li #price .price-promotion s{text-decoration:line-through; color:#F00}
ul#related li #price .or, ul#product li #price .or b{font-size:11px;}
ul#related li #price .or b{color:#F00;}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Acho que ele quiZ diSer que não precisa desta linha

 

RewriteRule ^(.+)/(.+)$ index.php?pg=$1&id=$2

coloque o outro $id na primeira linha mesmo

RewriteEngine On

RewriteRule ^(.+)/$ index.php?pg=$1&id=$2

 

Pois se não me engano automaticamente ele gera o /pagina/5

 

Olhe esse video

Url amigavel

Compartilhar este post


Link para o post
Compartilhar em outros sites

Estude Expressões Regulares

 

 

o ^ no começo, é pra indicar 'inicio'

o $ no final, indica que a ER acabou

o () é um 'grupo'

o [] é para indicar uma lista

o ^ no inicio da lista, é para 'negar'

no caso então, você está negando a barra dentro da lista

 

 

Vai casar com uma string que não começa, e não termina com barra.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Mas william, eu nao utilizo o [(^/)] e sim (.+) no meu .htaccess , so que:

 

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)/$ index.php?pg=$1 [L]
RewriteRule ^(.+)/(.+)$ index.php?pg=$1&id=$2 [L] #ele acha que a url do css faz parte, e nao acha o arquivo

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tá, só expliquei o ^([^/])$ pq você perguntou.

 

veja:

RewriteRule ^(.+)/(.+)$ index.php?pg=$1&id=$2 [L] #ele acha que a url do css faz parte, e nao acha o arquivo

ali, por causa da barra /

está sendo reescrito achando que é para 'entrar nos diretorios' também.

 

procure pelas flags com esse [L] (last), que você colocou ai.

 

isso aqui:

.+ é um curinga guloso.

Eu te disse no inicio, para mudar essa ER, deixando menos guloso.

Compartilhar este post


Link para o post
Compartilhar em outros sites

como que poderia fazer ?

 

tipo , tentei assim

 

RewriteRule ^([a-z]+)$ index.php?pg=$1 
RewriteRule ^([a-z]+)/([a-z0-9]?)$ index.php?pg=$1&id=$2 

 

so que as vezes, esse ?pg=$1&id=$2 o id é assim : 1-nome-do-produto

 

e ele não reconhece... por que ?

Compartilhar este post


Link para o post
Compartilhar em outros sites

porque: 1-nome-do-produto não casa com: [a-z]+

Compartilhar este post


Link para o post
Compartilhar em outros sites

Então a ordem está errada, e cadê a barra ?

 

para que:1-nome-do-produto

seja traduzido para:

 

 

?id=1&pg=nome-do-produto

 

você deve mudar completamente a tua ER

enfim, voltando ao problema inicial, pesquise pelo que postei, que irá resolver. (er menos gulosa, flags..)

sem o htaccess funciona ?

 

apartir do diretorio em que o css está, você tem uma pasta: images ?

Compartilhar este post


Link para o post
Compartilhar em outros sites

é que o 1 seria o id do produto, mas se eu apenas colocar o nome, e colocar ([a-z]) ele pega direitinho ?

 

Mas como eu poderia fazer para que ele pegasse o "-" ?

 

Sim, o css funciona, tenho a pasta images, sem o .htaccess, funciona direitinho...

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.