[英]How to redirect page with htacess without sending id
I have a problem with .htacces
url-rewritting. 我对.htacces
网址重写有问题。
I have a folder called dir
and in it I have three files 我有一个名为dir
的文件夹,其中有三个文件
.htaccess
is empty, i.php
is empty too but in index.php
I have .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>';
}
When I hover over echo
outputs a link like 当我将鼠标悬停在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
So, when I click on it, it takes me where I want, but I need to get rid of the id which in this case is 101
I want the link only to be localhost/dir/i/today-in-news
when I click on it. 因此,当我单击它时,它将带我到我想要的位置,但是我需要摆脱ID(在这种情况下为101
的ID,我希望当我访问时,链接仅是localhost/dir/i/today-in-news
点击它。 I have tried everything I could, but failed without any result. 我已经尽力了,但是没有任何结果。
This code will pass that title through to i.php
where you can then pull it from the database or whatever. 这段代码会将标题传递给i.php
,您可以在其中从数据库或其他任何东西中提取标题。 Take a look here for some .htaccess information. 在这里查看一些.htaccess信息。
index.php : 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 : .htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^i\/([a-zA-Z0-9_-])+\/?$ i.php?title=$1 [L]
</IfModule>
i.php i.php
$title = $_GET['title'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.