CodeForGood
CodeForGood

Reputation: 749

Hiding controller and method from the URL but show only title name

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

Upvotes: 0

Views: 118

Answers (2)

Sinf
Sinf

Reputation: 123

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 !

Upvotes: 0

Aman Maurya
Aman Maurya

Reputation: 1325

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

Upvotes: 1

Related Questions