我的网址是这样的:
(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]
它确实切断了查询字符串,但数据库查询不再有效。
我该怎么做?
非常感谢!
最佳答案
你不能 - 但如果你真的想要......:) 把值放在 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
关于php - mod_rewrite 截断查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30332498/