【问题标题】:Apache rewrite query string to CodeIgniter like URLApache 将查询字符串重写为类似 URL 的 CodeIgniter
【发布时间】:2011-09-09 11:36:37
【问题描述】:

这是一个带有查询字符串的示例 URL。 keyword 是用户在我的网站中搜索或从其他网站、搜索引擎等重定向的任何内容。

http://example.com/search.php?q=keyword

和等效的 CodeIgniter URL

http://example.com/search/now/keyword(搜索 = 控制器,现在 = 方法)

如何在 Apache .htaccess 中重写 URL 以创建类似 CodeIgniter 的 URL?

【问题讨论】:

  • 你确定这是你想要的吗?

标签: php .htaccess codeigniter mod-rewrite query-string


【解决方案1】:
RewriteRule ^/?search/now/(.*)$ /search\.php?q=$1

或者你可以隐藏url查询

RewriteRule ^search.php?id=(.*)$ /search.php [L,R=301]

【讨论】:

    【解决方案2】:

    首先你不想指向一个 php 文件。 CI 只有 index.php,如果你不顾一切可以将所有 search.php 指向 index.php...

    我会在这个基础上接近它......

    将表单发布到控制器,使用表单验证使输入安全,获取变量并像这样使用重定向功能

    redirect('/search/'.$this->input->post('q') );
    

    【讨论】:

      猜你喜欢
      • 2015-04-27
      • 2019-02-13
      • 2021-01-06
      • 2012-10-08
      • 1970-01-01
      • 1970-01-01
      • 2016-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多