Change link with . htaccess

Asked

Viewed 112 times

3

I have the following link

 http://127.0.0.1/site/noticia/12(cod_da_noticia)

I wonder how I can leave the link like this

 http://127.0.0.1/site/noticia/12(cod_da_noticia)/queria colocar o titulo aqui

link in . htaccess

 RewriteBase /
 RewriteEngine On
 RewriteRule ^site/noticia/([^/]+)$ site/index.php?op=28&cod=$1 [L,QSA]

href

href="../noticia/<?php echo $registo['cod_noticia'];?>">

1 answer

1


Try it this way:

RewriteEngine On

RewriteRule ^site/noticia/([a-z0-9-]+)/(.*)/?$ /site/index.php?op=28&cod=$1 [NC,L]

  • Thx. The title appears like this Graduations%20dos%20Judocas%20de%202016, how can I exchange %20 for -

  • I use a php function to treat titles by removing the special characters and spaces by substituting everything by - and saved in the database along with the news table in a field for the url, so I don’t need to inform the news id whenever I need to searchla, I can simply search the url, making it your url will be more beautiful and in the code you can use as follows Rewriterule site/noticia/([a-Z0-9-]+)/? $ /site/index.php? op=28&campo_da_url_na_tabela_noticia=$1 [NC,L]

  • $string = $register['Title']; $string = str_replace(' ', '-', $string); meto a $string in href made goes from each one’s engine

Browser other questions tagged

You are not signed in. Login or sign up in order to post.