0

.htacces我对url 重写有问题。

我有一个文件夹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在我点击它时出现。我已经尽我所能,但没有任何结果。

4

1 回答 1

1

此代码会将标题传递到i.php您可以从数据库或其他任何地方提取它的位置。在这里查看一些 .htaccess 信息。

索引.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'];
于 2013-04-14T21:50:12.293 回答