Slimtugo
Slimtugo

Reputation: 97

codeigniter - changing url for better SEO

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.

Upvotes: 0

Views: 924

Answers (5)

Muhammad Sadiq
Muhammad Sadiq

Reputation: 1155

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

Upvotes: 0

Jens
Jens

Reputation: 2075

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

Upvotes: 2

nielsstampe
nielsstampe

Reputation: 1364

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.

Upvotes: 1

user1844105
user1844105

Reputation: 48

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


Upvotes: 0

Venkata Krishna
Venkata Krishna

Reputation: 4305

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

Upvotes: 0

Related Questions