Alex
Alex

Reputation: 6655

Rewriting a GET URL

I'm using codeigniter to create a search page. I'd like to rewrite a GET url to work with CI.

Example

http://mysite.com/en/search?search=widgets

becomes

http://mysite.com/en/search/widgets

I thought I could do this in the routes.php, but it doesn't seem to grab the stuff after the ?. So now i'm thinking as a rewrite in .htaccess. Is this a good idea? What would the rewrite rule be?

Upvotes: 3

Views: 89

Answers (3)

Arda
Arda

Reputation: 6936

$searchtext = $this->url->segment(2);

should get the value "widget" in codeigniter. (Sorry if I got the question wrong).

Upvotes: 0

Vamsi Krishna B
Vamsi Krishna B

Reputation: 11490

$route['en/search/(:any)'] = "en/search/$1";

What is basically does is remap anything with /en/search/something to en class , search method and the search query will be passed as parameter .

using :any is not generally recommended, but you can also use custom regex if you want to be more specific regarding the characters that you want to allow.

Upvotes: 0

dynamic
dynamic

Reputation: 48131

You should use only the CI routing protocol. Anyway if you want to use .htaccess is this:

RewriteEngine On
RewriteRule ^en/search/([a-z]+)  /en/search?search=$1 [L]

Upvotes: 1

Related Questions