Codeigniter重写url get方法(url友好)


codeigniter rewrite url get method(url friendly)

我试图在使用get方法时重写codeigniter url。我为我的项目(一个商店)编写了一个搜索引擎,它工作得很好,但不是很url友好。当前url为:

shopping/search?query=cat

Shopping是控制器,search是方法,query是被搜索的get参数,在本例中是cat。

我想改变的是使url看起来像这样:

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>

试试这个:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/shopping/search/?$
RewriteCond %{QUERY_STRING} ^query=([^&]+)$
RewriteRule . /shopping/search/%1? [R=302,L]
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

如果您想要永久重定向,请替换为以下内容:

RewriteRule . /shopping/search/%1? [R=301,L]