RoutingTechniques in code-igneter

If you are using code-igneter then it have a very nice feature to rewrite your website url using route.php and you can make your site seo friendly very easily.

(1)-Suppose if you want to redirect all link which is start with name page after your base url like  

example :

Now i want to redirect this link to my home(This is controller name) controller ,and call function cms_page then i write below code :

$route['page/(:any)'] = "home/cms_page/$1";

Description : Now when i type this url in my browser then it will redirect in my home controller and function cms_page

(2)- In some situation suppose you want to redirect all link on a perticular controller but rest of some link you don't want to be redirect .In this see below 

example :

$route['^(?!login|camping|managepages|setting|home)\S*'] = "campground/viewdetail/$1";

Decription :In the above example i want to be redirect all links in viewdetail function in  campground controller.But i don't want to be redirect if url contain above controller name which is display in bold letter .like login ,camping , managepages, setting ,home /search/ /adminsetting/

Using above example route code rest of all these links will be redirect on viewdetail in campground controller.

Post a Comment

Previous Post Next Post