0

I want to know whether it is possible to write pretty URLs in Code igniter or not? I mean i have a code igniter project in which i am displaying data from uri segments like this:

http://myproj.local/category/subcategory/64/239

where 64 is the id of my category (e.g Garden Products )and 239 is my subcategory id (e.g Brushes).

Is there anyway I could write URLs like this in code igniter:

For categories:

http://myproj.local/Garden Products/

http://myproj.local/Household Range/

and for subcategories:

http://myproj.local/Garden Products/Brushes/

http://myproj.local/Household Range/Buckets/

Just like wordpress or other CMS.

IN SHORT,I WANT MY CODE IGNITER MVC framework TO DISPLAY URLs /Pages like these:

http://myproj.local/Garden Products/Brushes/

http://myproj.local/Household Range/Buckets/

Is this the kind of thing that can be achieved in the Code igniter or not?? IF YES, then how can I do this and how can i write this in code igniter ??What approach shall i use to achieve this ? I would appreciate if you could help me in this regard.Thanks

tereško
  • 58,060
  • 25
  • 98
  • 150
Bilal Khalid
  • 95
  • 5
  • 22

4 Answers4

2

I have answered a simular question on this before.

Check this out and see if it helps.

Other options include database driven routing, take a look at this link.

Also there is an article/example on reverse routing here that may prove helpful.

Community
  • 1
  • 1
Rooneyl
  • 7,802
  • 6
  • 52
  • 81
  • @Rooneyl.But it gives me an idea to replace ids with the names.My question is : How can make my url dynamic like wordpress etc as mentioned above: For example ( http://myproj.local/Garden Products/Brushes/ ) AND ( http://myproj.local/Household Range/Buckets/ ).Is this achievable in codeigniter?If yes,then how can I do this?? – Bilal Khalid Dec 06 '12 at 09:44
  • @BilalKhalid you could make every request go to a the default controller and have the look up function there where the first parameter is the category, second the sub category, the third the id of the product. – Rooneyl Dec 06 '12 at 10:12
  • @Rooneyl.How would i rename my URLs?And how would my controller check whether it is function name or my category or subcategory??Any example? – Bilal Khalid Dec 06 '12 at 10:18
  • @BilalKhalid I have updated my answer with some links to other resources, they should get you to where you want to be. – Rooneyl Dec 06 '12 at 11:45
  • @Rooneyl.Thanks Rooney.I appreciate your help. – Bilal Khalid Dec 06 '12 at 11:53
  • @Rooneyl.Rooney could you help me with this?http://stackoverflow.com/questions/13588127/url-redirection-in-wamp-codeigniterapache-error-loghelp-me-plz/13588257#comment18632397_13588257 .I am stuck for more than two weeks and noone could help me with this.Kindly help me. – Bilal Khalid Dec 09 '12 at 00:26
  • @BilalKhalid do you still want help with that question, you have accepted an answer? If so give me you email address. – Rooneyl Dec 09 '12 at 18:30
  • @Rooneyl.Yes rooney.i partially accepted that question as it helped me lil bit in terms of .htaccess file but couldn't solve the apache errors and url formatting and redirection.After this,I sent my project to that person to help me but he never got back to me.I have changed the accept status of the answer as you pointed out as it is still unresolved.Can you help me with this? – Bilal Khalid Dec 10 '12 at 08:10
0

SEO doesn't recommend spaces in URL

you can refer to seomoz

Waqleh
  • 9,741
  • 8
  • 65
  • 103
  • @WaleedAkleh.Ignore spaces.How can make my url dynamic like wordpress etc as mentioned above: For example ( myproj.local/Garden Products/Brushes/ ) AND ( myproj.local/HouseholdRange/Buckets/ ) instead of (http://myproj.local/category/subcategory/64/239).Is this achievable in codeigniter ?If yes,then how can I do this?? – Bilal Khalid Dec 06 '12 at 09:47
0

Instead of using IDs, you can use unique string names so http://myproj.local/category/subcategory/64/239 becomes just http://myproj.local/category/subcategory and then use routes to redirect anything that's not e.g. images, css, etc. whatever you use, to be redirected to a common controller/method which takes category and subcategory as parameters.

Also, CodeIgniter has a nice helper function url_title that will help you write unique string representations of your categories and subcategories... You just need to make sure they are unique.

The other way is like others said, make a whitelist in your routes file and make each redirection manually.

Shomz
  • 37,421
  • 4
  • 57
  • 85
-1

This why you have the routes file,however i know only of hardcoing categories, dunno about doing that automatically. you can do something like this :

$routes['Gardents/Products'] = "category/subcategory/64/239";
eric.itzhak
  • 15,752
  • 26
  • 89
  • 142