繁体   English   中英

如何使用Htacess重定向页面而不发送ID

[英]How to redirect page with htacess without sending id

我对.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的ID,我希望当我访问时,链接仅是localhost/dir/i/today-in-news点击它。 我已经尽力了,但是没有任何结果。

这段代码会将标题传递给i.php ,您可以在其中从数据库或其他任何东西中提取标题。 在这里查看一些.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'];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM