簡體   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