3
I am developing a dynamic web site m pages and url friendly, my problem is the following:
When I put the id on the link to view the details of the property <a href="/imovel?id<echo $row['id_imovel']>">
, the immovable.php file does not receive the id that was sent via get.
In the url, when immovable it includes immovable.php, but when immovable? id=3174 for example not included.
HTACCESS
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?pagina=$1
PHP:
function getHome(){
$url = $_GET['pagina'];
$url = explode('/', $url);
$url[0] = ($url[0] == NULL ? 'content' : $url[0]);
if(file_exists('tpl/'.$url[0].'.php')){
require_once('tpl/'.$url[0].'.php');
}elseif(file_exists('/tpl/'.$url[0].'/'.$url[1].'.php')){
require_once('tpl/'.$url[0].'/'.$url[1].'.php');
}elseif(file_exists('/tpl/'.$url[0].'/'.$url[1].'/'.$url[2].'.php')){
require_once('tpl/'.$url[0].'/'.$url[1].'/'.$url[2].'.php');
}else{
require_once('tpl/404.php');
}
How to solve?
Solved buddy! Thanks! How can I hide the id, leaving immovable/3174 for example?
– Igor Silva
@Igorsilva edited the answer, see if it helps.
– Guilherme Nascimento
Insert the option in my htaccess to any page with ID and it didn’t work. Do I have to handle the id in the getHome function of the php code above? This link goes to immovable page with id: <a href="<? php echo DIR? >/immovel? id=<? php echo $id;?>">.
– Igor Silva
No @Igorsilva I passed by
&id=$1
then just use$_GET['id']
.– Guilherme Nascimento
Would that be: <a href="<? php echo DIR? >/imovel/<? php echo $id;?>">
– Igor Silva
@Igorsilva said that :) because the
index.php?pagina=imovel&id=$1 [QSA]
already interprets theid=
, then the address should be something likehttp://exemplo/imovel/10001
and when to use$_GET['id']
will return10001
for example– Guilherme Nascimento
Returned Not Found, the end of my url is this:www.site.com/exclusive/immovel/3239
– Igor Silva
@Igorsilva the folder
exclusive
is there? note that I used^imovel/(\d+)$
and not^exclusive/imovel/(\d+)$
. You are changing the url pattern, there is no way mod_rewrite understands such a change if you do not edit . htaccess to it.– Guilherme Nascimento
My site n is in the root, its url is like this: site.com/exlcusive/immovel/ID, I will insert the exclusive/immovel to see if it works.
– Igor Silva
@Igorsilva You mean that
exlcusive
is a real folder?– Guilherme Nascimento
Yes, you can post the site url here?
– Igor Silva
@Igorsilva You can! Only one thing answers the . htaccess is in which folder?
– Guilherme Nascimento
This is the website: http://himoveis.com/exclusive/ htaccess is in the exclusive folder.
– Igor Silva
@Igorsilva we’ll talk tomorrow :)
– Guilherme Nascimento
Vlw! Thank you very much!
– Igor Silva