mod_rewrite切断查询字符串

时间:2015-05-19 17:39:33

标签: php mysql mod-rewrite

我的网址看起来像这样:

(something).php?kid=[someNumber]

e.g。

index.php?kid=9

abc.php?kid=23

我使用这些数字来查询数据库以创建子菜单。

如何更改网址以便查询字符串不可见但我仍然可以查询数据库?

我的方法:

RewriteEngine On
RewriteBase /
RewriteCond      %{QUERY_STRING}    ^kid=([0-9]+)$
RewriteRule      (.*)               $1?     [R=permanent]

它会切断查询字符串,但数据库查询不再起作用。

我该怎么做?

提前非常感谢!

1 个答案:

答案 0 :(得分:0)

你绝对不能 - 但如果你真的想...... :)把价值放在cookie中

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^kid=([0-9]+)$
RewriteRule ^ - [co=kid:%1:%{HTTP_HOST}:7200:/]
# This Cond to avoid endless redirect
RewriteCond %{QUERY_STRING} .
RewriteRule (.*)  $1?  [R=permanent]

然后在php中询问example.com/Thsng?kid=12345

session_start();
echo '$_COOKIE["kid"]; // echo 12345