【问题标题】:hidequery string parameters from the url using url rewriting使用 url 重写从 url 隐藏查询字符串参数
【发布时间】:2012-04-21 13:23:27
【问题描述】:

在我的 php 网站中,我需要以特定的方式显示我的骨灰盒

我需要隐藏查询字符串参数,只想在 URL 中显示值 即

mydomain.com/city.php?place='usa'&id=2

我需要展示

my domain.com/city-2/usa

有可能吗?

请帮助我。我的情况很严重。

提前致谢

【问题讨论】:

  • “我的情况很严重。” --- 这样的事情永远不会对你有好处(至少在这里)
  • Dnt 对 Php 有很多了解,但你想要的是基于 REST 的 API。
  • urn 错字是一个有趣的错误,因为 URN 实际上是 URL 的(很少使用)兄弟
  • @shashankaholic:你可能不明白 REST 是什么,真的 :-)
  • @shashankaholic: en.wikipedia.org/wiki/Representational_state_transfer 而OP想要的与整个标准无关,他只是想重写一个小url

标签: php html url-rewriting


【解决方案1】:

是的,有可能:

RewriteEngine On
RewriteBase /

RewriteRule ^city-(\d+)/(.*) city.php?place=$2&id=$1

您需要将其放入您网站的网络根目录中的.htaccess。要使其正常工作,您需要启用 .htaccess 解析并启用 mod_rewrite apache 模块(假设您将 apache 作为 Web 服务器)。

更多内容请关注official documentation

【讨论】:

  • 你应该在你的回答中添加更多的词,比如 RewriteRule 到底是什么,它去哪里等等。
猜你喜欢
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 2011-11-16
  • 1970-01-01
  • 1970-01-01
  • 2021-02-10
  • 1970-01-01
相关资源
最近更新 更多