【问题标题】:Get search value using friendly URL使用友好 URL 获取搜索值
【发布时间】:2020-11-25 16:15:14
【问题描述】:

我正在为个人资料页面使用 htaccess 友好 URL,例如:

RewriteRule ^([^/]+)/?$ profile.php?id=$1 [L]

如果我打开链接,例如 /some-user,它可以正常工作,并打开个人资料页面。

现在在此个人资料页面中,我有搜索表单,我如何从链接中获取搜索值,因为当我提交时,我得到了这种链接: /some-user?search=somekeywod

提交时,我需要使用搜索值打开该配置文件的 url。

我的搜索表单很简单:

<div class="input-group md-form form-sm form-2 pl-0">
  <input class="form-control my-0 py-1 lime-border" type="text" placeholder="Search..." name="search" aria-label="Search">
  <div class="input-group-append">
    <button type="submit" class="input-group-text lime lighten-2" id="basic-text1"><i class="fa fa-search text-grey"
        aria-hidden="true"></i></button>
  </div>
    </form>```

【问题讨论】:

  • 这能回答你的问题吗? Rewrite GET Query String using .htaccess
  • 没有。我已将 profile.php?id=some-user 重写为 /some-user。现在在里面我需要在该用户配置文件中使用搜索表单,所以如果我点击搜索,它需要打开该用户配置文件并给我 $_GET["search"] 值。

标签: php


【解决方案1】:

在你的 htaccess 文件中试试这个

RewriteEngine on
RewriteRule ^/profile/([0-9]+)/ /profile.php?id=$1 

【讨论】:

    猜你喜欢
    • 2014-11-09
    • 2011-08-31
    • 2012-06-18
    • 2010-12-11
    • 2012-10-09
    • 2011-12-17
    • 2013-10-16
    • 2021-06-12
    • 1970-01-01
    相关资源
    最近更新 更多