我遇到了.htacces
网址重写的问题。
我有一个名为dir
的文件夹,其中有三个文件
.htaccess
为空,i.php
也为空但 index.php
我有
$sql = mysql_query("SELECT * FROM clients ORDER By id DESC LIMIT 10");
while($row = mysql_fetch_array($sql)){
$url = "i/$row[id]/".preg_replace('/[^a-zA-Z0-9-_]/', '-', $row['company']);
echo "<a href='".$url ."'>".$row['company'].'<br/ ></a>';
}
当我将鼠标悬停在echo
输出时,会显示
localhost/dir/i/101/today-in-news
localhost // is localhost obviously
dir // is a folder where I keep index.php and i.php files
i // is i.php
101 // is the id of the news
today-in-news // is the title of the news
所以,当我点击它时,它会带我到我想要的地方,但我需要摆脱id,在这种情况下是101
我希望链接只有localhost/dir/i/today-in-news
时我点击它。我尽我所能,但没有任何结果就失败了。
答案 0 :(得分:1)
此代码会将该标题传递给i.php
,然后您可以从数据库或其他任何位置将其拉出。看看here了解一些.htaccess信息。
<强>的index.php 强>:
$sql = mysql_query("SELECT * FROM clients ORDER By id DESC LIMIT 10");
while($row = mysql_fetch_array($sql)){
$url = "i/".preg_replace('/[^a-zA-Z0-9-_]/', '-', $row['company']);
echo "<a href='".$url ."'>".$row['company'].'<br/ ></a>';
}
<强>的.htaccess 强>:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^i\/([a-zA-Z0-9_-])+\/?$ i.php?title=$1 [L]
</IfModule>
<强> i.php 强>
$title = $_GET['title'];