简体   繁体   中英

Pretty URLs for Code igniter

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 (eg Garden Products )and 239 is my subcategory id (eg 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

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.

SEO doesn't recommend spaces in URL

you can refer to seomoz

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

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";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM