Apache mod_rewrite - 如何从 url 隐藏 $_GET 变量
当我调用页面时,
http://localhost/books-123-name.html?language_id=1
浏览器中会显示以下链接:
http://localhost/books-123-name.html
但会保留值 language_id=1
这该怎么办?
谢谢。
When I call the page
http://localhost/books-123-name.html?language_id=1
to appear in the browser the following link:
http://localhost/books-123-name.html
but will keep the value language_id=1
How can this be done?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了 GET 参数之外,还有多种方法可以存储有关请求的信息。一种是使用 cookie,您可以将 language_id 存储在 cookie 中。使用 cookie 的一个特殊情况是使用会话。您还可以在 POST 请求中传递 language_id,因为 POST 参数对用户不可见。您还可以使用 mod_rewrite 仍然使用 GET 参数,但使它们更漂亮。
There are several ways to store information about requests other than GET parameters. One is using cookies, and you could store language_id in a cookie. A special case of using cookies would be using a session. You could also pass the language_id in a POST request, because POST parameters are invisible to the user. You might also use mod_rewrite to still use GET parameters, but make them prettier.
简而言之,你不能。
浏览器需要这些值才能读取它们。
您可以尝试读入它们,对它们执行某些操作,然后重定向到不带参数的页面。
或者使用
POST
。但更重要的是,为什么?
In short, you can't.
The browser needs those values there in order to read them.
You could try reading them in, doing something with them and then redirecting to a page without the parameters.
Or use
POST
.But more importantly, why?
就像 jakenoble 所说的使用
发布
。或者也许你可以使用不同的 url 模式,例如
例如
http://localhost/en/books-123-name.html
>到
例如
http://localhost/books-123-name.html?language_id=1< /代码>
Like jakenoble said use
POST
.Or Maybe you can use a different url pattern like
e.g.
http://localhost/en/books-123-name.html
to
e.g.
http://localhost/books-123-name.html?language_id=1