-2
I’m working on a PHP ad system for autonomous professionals where I’m having a hard time including the title of this ad within the page URL making it a friendly URL. I found some similar issues, but unfortunately I could not resolve the issue:
In this case, currently the URL of the ad page is so:
Current URL:
https://meusite.com.br/anuncio?id=10
And I would like the URL to be as follows below where after / is inserted the value of a variable in php:
URL desired:
https://meusite.com.br/anuncio/titulo-do-anuncio-aqui
To create a link to redirect the user to the ad page, insert a variable called $Row['id'] inside a href as below:
<a href="anuncio?id='.$row['id'].'">'.$row['tituloAnuncio'].'</a>
As the link tag above, the $Row variable comes from a related while a query select that runs correctly within the page.
Finally, I tried to configure Htaccess as follows below, but because I am a beginner in this area, I could not properly configure as well as find a correct way to configure the desired URL:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^anuncio\/?([0-9]+)\/?(.+)\/?$ anuncio.php?id=$1
In the case how do I use the value of the variable $Row['titloAnuncio'] inside the URL of the ad page as below?
https://meusite.com.br/anuncio/professor-particular-ou-online
I don’t quite understand... Your link uses
$row['id']
which I suppose is numerical and wants the URL to be using$row['tituloAnuncio']
? If anyone accesseshttps://meusite.com.br/anuncio?id=10
you want a redirect to be made or you want the URL to point directly to the title?– Papa Charlie
Thanks for the feedback @Papacharlie. The idea would be this same if possible. In the case currently the page is accessed by this url format
https://meusite.com.br/anuncio?id=10
where the id is identified as$row[id]
, but the idea would be that the url would look like thishttps://meusite.com.br/anuncio/titulo-do-anuncio-aqui
, but I don’t know how to do this configuration as much as in htaccess or php.– Michel Xavier