我很久以前用mysqli开发了一个动态网站,没有php框架,现在我想用htaccess改变URL,我想这样做:
www.website.com/post.php ? id = 1
www.website.com/post/post_title.html
和我使用的查询是:
$query = $mysqli->query("SELECT * FROM articles WHERE id_article='".$_GET['id']."'");
$articles = $query->fetch_object();
是否可以更改url?如果是,我是否也需要更改查询?
在站点根目录下的。htaccess文件中试试
RewriteEngine on
RewriteRule post/(.*) post.php?article_name=$1 [L,QSA]
然后你必须让post.php根据$_GET['article_name']
的接收来查找id_article
作为旁注,您发布的$mysqli->query
代码容易受到SQL注入的影响,因为它不会在$_GET['id']
上调用addslashes
或mysql_real_escape_string
。