0

How can i change the following url

from:

http://localhost/autoquest/index.php/autos?category=camry

to:

http://localhost/autoquest/index.php/autos/camry

using codeigniter. The category option camry comes from a select option such as:

<select id="category" name="category" onchange="this.form.submit()">
    <option value="camry">car 1</option>
    <option value="octavia">car 2</option>
    <option value="volvo">car 3</option>
</select>

I think the second url is better in terms of SEO am i wrong?

Thanks all.

Slimtugo
  • 97
  • 1
  • 9

5 Answers5

2

Did you have a look at config/routes.php? You can define rewrite rules there. And if you set the config parameter index_page (in config/config.php) to be empty, you can remove the index.php too. But you should read the documentation about urls: http://ellislab.com/codeigniter/user_guide/general/urls.html

Kumar V
  • 8,810
  • 9
  • 39
  • 58
Jens
  • 2,050
  • 1
  • 14
  • 30
1

Have you enabled query strings in your Codeigniter Config?

That's application/config/config.php around line 155:

$config['enable_query_strings'] = FALSE;

If this is set to FALSE you shouldn't be able to use query strings as you suggest you already are, but in fact use the default search-engine friendly segment based URLs. As stated in the userguide. So you URL automatically would be

http://localhost/autoquest/index.php/autos/camry

instead of

http://localhost/autoquest/index.php/autos?category=camry

For more information please take a look at the fantastic userguide here: http://ellislab.com/codeigniter/user_guide/general/urls.html

Hope this helps.

Kumar V
  • 8,810
  • 9
  • 39
  • 58
nielsstampe
  • 1,336
  • 1
  • 15
  • 25
  • Thanks for your response. Your solution is almost what I want but the problem is that some part of the site already use querystring and I don't want to optimize those areas for SEO. Thanks – Slimtugo Nov 21 '12 at 12:41
  • CodeIgniter was not designed to be used with QueryString's. Whilst it is possible, I would advise you to use the correct routing methods that are provided and described within the http://www.codeigniter.com/user_guide – Gavin Nov 21 '12 at 14:38
0

You can do it this way ........when you submit this form call a javascript function. Send your option value as an argument to that function. In that function use window.href function assign your base_url + '/'+ controller_name+'/'+ function_name_in_controller +'/'+ option_value..... .

From that function in controller call your view file.......

Venkata Krishna
  • 4,287
  • 6
  • 30
  • 53
0

Along with the above,

You can remove index.php by writing the following code in your .htaccess in root.


RewriteEngine On

RewriteBase /yoursitefolder

RewriteCond %{REQUEST_URI} ^system.*

RewriteCond $1 !^(index.php|images|js|css|robots.txt)

RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [L]

Options -Indexes

DirectoryIndex index.php


0

-Try this -change in routes.php

$route['autos'] = 'YourController/yourMethod/$1";

-and change make your link in veiw as like this.

<?php echo base_url().'autos/'.$parameter;?>

-And url without index.php is much better for SEO and you can remove it by adding below code to your .htaccess file,which is in root directory and if not present than create it and paste the following code in it..

<ifModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ index.php/$1 [L]
</ifModule>
Muhammad Sadiq
  • 1,147
  • 11
  • 13