[英]mod_rewrite / query_string
我從一個mysql數據庫中獲得了一些基本結果並將其列在頁面上,在頁面上我添加了帶有變量user_id的鏈接:
href=\"http://localhost/TESTING/template.php?user_id=$user_id\" >click here
在template.php文件中,我將獲得$ user_id並顯示相關的完整數據。
問題是我不希望user_id = 249 http://localhost/TESTING/template.php ?** user_id = ** 249在網址中顯示我喜歡的內容“ http:// localhost / TESTING / template.php / 249 “。
我一直在研究這幾天但沒有成功,這可能嗎? 或者模板文件是否需要顯示user_id = $ user_id才能獲取變量?
=====================
要更新:我添加了代碼
RewriteEngine On
RewriteBase / TESTING /
RewriteRule ^ template.php /([0-9] +)(/)?$ template.php?user_id = $ 1 [L]
將鏈接變量更改為href =“localhost / TESTING / template.php / {$ user_id}”>單擊此處
重寫現在可以工作,但是我沒有用$ user_id = $ _GET [“user_id”]獲取變量; 在template.php頁面上
我將以下內容添加到template.php頁面,以查看通過url傳遞的內容:
<?php
ini_set('display_errors',1);
echo '<b>$_GET Variables</b><pre>';
var_dump( $_GET );
echo '</pre>';
?>
並得到以下回應:
$ _GET變量
array(1){[“user_id”] => string(2)“21”}
如何獲得變量?
===========
現在更新有效! 鏈接中的{$ user_id}不是{user_id} - 可以發誓我試過兩種方式。
我不想成為一個人,但是互聯網上有很多手冊,例如
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
通過示例解釋了您需要的一切。 你試過什么了? 所以我們可以解釋什么是錯的。
請注意,mod_rewrite僅適用於Apache服務器。
RewriteEngine On
RewriteBase /TESTING/
RewriteRule ^template.php/([0-9]+)(/)?$ template.php?user_id=$1 [L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.