Search code examples
codeigniterseocodeigniter-routing

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.


Solution

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