skip to Main Content

I looked at the suggested answer(possible duplicate as stakoverflow says). It provided help but didn’t solve the problem as it won’t help create clean URL as per my needs. It has controller as part of the URL which I don’t want to see as mentioned below.

I am developing a tutorial site in Codeigniter, and looking for a way to generate SEO friendly URL like

www.crdlabs.com/how-to-use-multidimensional-arrays

instead of

www.crdlabs.com/home/index/how-to-use-multidimensional-arrays.

Can anyone share his ideas? Thank you

2

Answers


  1. First you need to hide the index.php from URL so create the .htaccess file on the root folder and add this code

    .htaccess

    DirectoryIndex index.php
    RewriteEngine on                       
    RewriteCond $1 !^(index.php|(.*).swf|forums|images|css|downloads|js|robots.txt|favicon.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ ./index.php?$1 [L,QSA] 
    

    Then open the routes.php file in the application/config/routes.php location
    and add this

    $route['how-to-use-multidimensional-arrays'] = 'home/how-to-use-multidimensional-arrays';
    

    This will work as URL as SEO friendly

    Login or Signup to reply.
  2. Add this to ur root .htaccess file :

    RewriteRule ^(.*)$ index.php?title=$1 [NC,L,QSA]
    

    Then in ur index.php get the title $title = $_GET[‘title’] and do what ever you like with it like do a query in ur database and return data based on the title !

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search