【问题标题】:.htaccess rewrite url parameters and keys.htaccess 重写 url 参数和键
【发布时间】:2020-07-23 07:39:35
【问题描述】:

我对如何使用 .htaccess 重写网址感到奇怪。 有人可以解释一下下面的重写吗?

原文:index.php?param1=value1 所需:index.php/param1/value1

和 原文:index.php?param2=value2 所需:index.php/param2/value2

param1 和 param2 是固定的,但它们的值不同。

在 index.php 上,我想用 $_[GET] 检索参数

我正在尝试这样的事情

RewriteCond %{QUERY_STRING} conf=(.+)

RewriteRule ^ /%1/? [R,L](.+)

对于 param1 = conf.

【问题讨论】:

  • 您是否已经进行了重写?
  • 请勿在评论区发布代码。编辑您的问题以包含它。

标签: php apache .htaccess url-rewriting


【解决方案1】:

重写规则看起来像

RewriteRule ^index.php/([^\/]+)/([^\/]+) /index.php?$1=$2 [L]

【讨论】:

  • 如果我想摆脱 index.php 而只拥有 mydomain.com/param1/value1 怎么办?
  • 去掉index.php/部分,变成RewriteRule ^([^\/]+)/([^\/]+) /index.php?$1=$2 [L]
  • htaccess.madewithlove.be 是帮助您测试重写的好工具。
猜你喜欢
  • 1970-01-01
  • 2023-03-19
  • 2017-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-16
  • 1970-01-01
相关资源
最近更新 更多