0
My normal url is:
http://localhost/paginas/noticias.php?id=1
I wish so:
http://localhost/paginas/noticias/1
id 1 is generated by php, I don’t know how to get it this way in htaccess.
0
My normal url is:
http://localhost/paginas/noticias.php?id=1
I wish so:
http://localhost/paginas/noticias/1
id 1 is generated by php, I don’t know how to get it this way in htaccess.
1
Create the htaccess file inside the folder ./paginas
and write the following contents:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^noticias/([0-9]+)$ noticias.php?id=$1 [L]
If you have pages other than.php news, then use it like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9\-_]+)/([0-9]+)$ $1.php?id=$2 [L]
In this case you can access pages that will be equivalent:
http://exemplo/paginas/noticias/8
=> http://exemplo/paginas/noticias.php?id=8
http://exemplo/paginas/blog/2
=> http://exemplo/paginas/blog.php?id=2
http://exemplo/paginas/produto/4
=> http://exemplo/paginas/produto.php?id=4
http://exemplo/paginas/artigo/5
=> http://exemplo/paginas/artigo.php?id=5
Note that for this you must activate mod_rewrite as explained in this link
Browser other questions tagged php mysql htaccess
You are not signed in. Login or sign up in order to post.
It didn’t work, it did Not Found
– Paulo Cavalcante
@Dinho was an htaccess error, change
RewriteCond %{REQUEST_FILENAME} -f
forRewriteCond %{REQUEST_FILENAME} !-f
, see that I edited the response with the corrected code.– Guilherme Nascimento
It worked, but when I open the page gives error in php saying that: Notice: Undefined variable: id.
– Paulo Cavalcante
Will it be if this is because of htaccess?
– Paulo Cavalcante
@Dinho No I tested here a php like this:
<?php

echo $_GET['id'];
and it worked, the error is in your php, it has nothing to do with .htaccess. How is your php?– Guilherme Nascimento
<?php $noticiass = mysql_query("SELECT * FROM 10cms_noticias WHERE id = $id") or die(mysql_error()); $id = $_GET['id']; ? > <? php $i = 0; while($Edit = mysql_fetch_assoc($noticiass)){ $i++; ? > <? php echo $Edit['title']; ? > <? php } ?>
– Paulo Cavalcante
@Dinho If you open the direct url so it will also give error
http://exemplo/paginas/noticias.php?id=8
the error is in your code, you set the variable after running the query, see that in the first select you already request the $id, but you only set it after, the right is<?php $id = $_GET['id']; $noticiass = mysql_query("SELECT * FROM 10cms_noticias WHERE id = $id") or die(mysql_error()); ?> <?php $i = 0; while($edit = mysql_fetch_assoc($noticiass)){ $i++; ?> <?php echo $edit['titulo']; ?> <?php } ?>
– Guilherme Nascimento
Let’s go continue this discussion in chat.
– Paulo Cavalcante
@Dinho Conseguiu?
– Guilherme Nascimento
It worked with her code, pulled everything, but I pulled a include from my top, and she ran out of style.
– Paulo Cavalcante
@Dinho This is because of the
BASE
, At each path directory the access level to CSS and JS changes the good thing is to create the folders at the root. This is already another problem, please create a question with details about how you use CSS and JS and talk about the problem with htaccess, tomorrow I answer, good night -- The problems of changing the link is already solved.– Guilherme Nascimento
Good evening. Thanks for your help.
– Paulo Cavalcante
@Dinho noticed that you have several answers in your questions, but you did not accept any as correct. To accept an answer as correct click on the drawing that is next to the answer that helped you the most. To understand how Stackoverflow works see this link: http://answall.com/tour
– Guilherme Nascimento
I didn’t even know it, it was bad kkk
– Paulo Cavalcante
@Dinho has other questions besides mine. Don’t worry, until tomorrow.
– Guilherme Nascimento