[英]mod_rewrite to chop off query string
My urls look like this: 我的网址看起来像这样:
(something).php?kid=[someNumber]
eg 例如
index.php?kid=9
or 要么
abc.php?kid=23
I use these numbers to query a database to create a submenu. 我使用这些数字查询数据库以创建子菜单。
How can I change the url so that the query string is not visible but I can still query the database? 如何更改URL,以使查询字符串不可见,但仍可以查询数据库?
my approach: 我的方法:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^kid=([0-9]+)$
RewriteRule (.*) $1? [R=permanent]
It does chop off the query string but the database query doesnt work anymore. 它确实切断了查询字符串,但数据库查询不再起作用。
How can I do that? 我怎样才能做到这一点?
Big thanks in advance! 预先感谢!
You mustn't - but if you really want...:) Put value in cookie 您可以-但如果您确实想要... :)将价值放入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]
ask example.com/Thsng?kid=12345
then in php: 问
example.com/Thsng?kid=12345
然后在php中:
session_start();
echo '$_COOKIE["kid"]; // echo 12345
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.