【发布时间】:2014-10-02 20:18:44
【问题描述】:
我正在尝试在使用 get 方法时重写 codeigniter url。 我为我的项目(一家商店)编写了一个搜索引擎,它运行良好,但对 url 不是很友好。 当前网址是:
shopping/search?query=cat
shopping是controller,search是method,query是被搜索到的get参数,本例中是cat。
我想要改变的是让网址看起来像这样:
shopping/search/cat
我一直在尝试以多种方式使用 .htaccess,但没有成功。这是我的 .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
【问题讨论】:
-
您只是在寻找
.htaccess解决方案吗?难道你不能修改搜索方法以在url中查找查询字符串而不是$_GET吗?应该像function search($query){...}一样简单 -
我没有使用 $_GET 我正在使用 codeigniter 获取输入。你能告诉我一个例子,说明我如何在没有 get 方法的情况下“捕捉”搜索输入吗?因为如果我有一个搜索表单,我必须通过 post 或 get 发送它。
标签: php .htaccess codeigniter codeigniter-url