Php 如何使我的网站使用干净的URL?
我下面的代码创建了诸如“site.com/image.php?id=12”之类的链接,但是有没有人在不为每个id手动创建页面的情况下,有没有技巧可以创建诸如“site.com/image/12”之类的链接Php 如何使我的网站使用干净的URL?,php,mysql,sql,clean-urls,Php,Mysql,Sql,Clean Urls,我下面的代码创建了诸如“site.com/image.php?id=12”之类的链接,但是有没有人在不为每个id手动创建页面的情况下,有没有技巧可以创建诸如“site.com/image/12”之类的链接 $result = mysqli_query($con,"SELECT * FROM tabl1 where name like '%$s%'"); while($row = mysqli_fetch_array($result)) { echo "<
$result = mysqli_query($con,"SELECT * FROM tabl1 where name like '%$s%'");
while($row = mysqli_fetch_array($result))
{
echo "<a href='image.php?id=" . $row['id'] . "'>" . $row['Name'] . "</a>";
echo "<br>";
}
它使用了我网站上的?id=12部分的id,所以我不确定如果我将其更改为清除URL,它将如何工作
任何帮助都是有用的,我是php的新手
编辑:
我创建了一个.htaccess文件并将其放入其中,但当我单击链接时,它仍然会转到image.php?id=12,我是否做错了什么?还有什么我必须做的吗 此网站为您提供服务
谷歌这个关键词:apachemod_,我读过,但没有成功。我需要更改我的php代码吗?如果您使用mod_rewrite正确配置apache,那么不需要更改代码。
RewriteEngine On
RewriteRule^image/id/([^/]*)\.php$/image.php?id=$1[L]
我创建了一个.htaccess文件并将其放入其中,然而,当我点击链接时,它仍然会转到image.php?id=12,我是不是做错了什么?还有什么我必须做的吗?你要去http://site.com/image/12
?或http://site.com/image.php?id=12
,并希望它转到http://site.com/image/12
automatically我不是这个意思,很抱歉弄错了。接受答案很好,这样其他人就知道他们可以继续下一个问题^^
$result = mysqli_query($con,"SELECT * FROM celeb where id like '$id'");
RewriteEngine On
RewriteRule ^image/id/([^/]*)\.php$ /image.php?id=$1 [L]
The original URL:
http://site.com/image.php?id=12
The rewritten URL:
http://site.com/image/12
htaccess:
RewriteEngine On
RewriteRule ^image/([^/]*)$ /image.php?id=$1 [L]