user3460046
user3460046

Reputation: 83

codeigniter rewrite url get method(url friendly)

i am trying to rewrite the codeigniter url when using the get method. I programmed a search engine for my project(a shop) which works fine, but is not very url friendly. The current url is:

shopping/search?query=cat

Shopping is the controller, search is the method and query is the get parameter that been searched, in this example it's cat.

What i want to change is to make the url to appear like this:

shopping/search/cat

I have been trying to do it with the .htaccess in many ways, but it didn't worked. Here is my .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>

Upvotes: 2

Views: 613

Answers (1)

Ankit Singhania
Ankit Singhania

Reputation: 1010

Try this :

<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>

Replace with below if you want a permanent redirect :

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

Upvotes: 0

Related Questions