【问题标题】:mod_rewrite to chop off query stringmod_rewrite 切断查询字符串
【发布时间】:2015-05-20 14:00:24
【问题描述】:

我的网址如下所示:

(something).php?kid=[someNumber]

例如

index.php?kid=9

abc.php?kid=23

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

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

我的方法:

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

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

我该怎么做?

提前致谢!

【问题讨论】:

  • 我该怎么做?”你没有。
  • 没办法美化url,还是让$_GET收到东西??
  • 正如我之前所说,不,你不能那样做。 apache 怎么知道要传递哪些值?!
  • 我以为只是重写了 url,但不知何故保留了原来的 url……哦,好吧,那没关系。谢谢!

标签: php mysql mod-rewrite


【解决方案1】:

你不能 - 但如果你真的想要......:) 将价值放入 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]

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

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

【讨论】:

  • 不客气!有帮助的别忘了采纳哦:)
猜你喜欢
  • 1970-01-01
  • 2014-07-27
  • 1970-01-01
  • 2018-10-15
  • 2011-03-11
  • 1970-01-01
  • 2012-02-05
  • 2018-05-11
  • 2016-03-26
相关资源
最近更新 更多