我想使用.htaccess文件製作友好的URL。但是,當我點擊鏈接,這是在HREF如何在使用htaccess重寫動態url時製作href
指定<a href="category.php?id= <?php echo "{$row['name']}"; ?>">Example </a>
$row['name']
是動態的。數據存在於MySQL數據庫中。
代碼(category.php):
<?php
if($_GET['id']){
$result = $_GET['id'];
}
echo "this is {$result} page";
?>
此傳遞的參數只是存儲在$result
變量並將其顯示在屏幕上。
代碼(.htaccess文件):
Options -Multiviews
RewriteEngine On
RewriteRule ^website/(.+)$ category.php?id=$1
,當我點擊鏈接它顯示像http://mydomain.com/category.php?id=Rohit
而不是http://mydomain.com/website/rohit
的URL。
但是,當我手動寫入URL到http://mydomain.com/website/rohit
它顯示相同的頁面。這表明.htaccess文件正在工作。我想單擊示例時直接顯示上面的URL。
一個例子
當我們點擊的維基百科頁面奧巴馬它去http://en.wikipedia.org/wiki/Barack_obama
但原鏈接的作品太 - http://en.wikipedia.org/w/index.php?title=Barack_obama
。兩頁都顯示相同的數據。 它們不會向用戶顯示第二個URL,而是顯示另一個。我想達到同樣的結果。
如何編寫鏈接以便重寫URL?
非常感謝。 你的代碼工作。 – Rahulkg007