Welcome Guest, Not a member yet? Register   Sign In
replace category ID on clean URL become category name
#1

[eluser]sihijau[/eluser]
Hi, i'm newbie in CI..
I can rewrite url to remove index.php and adding suffix to it using mod_rewrite on .htaccess
this is content of my .htaccess file:

Code:
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /base_url
  RewriteCond %{REQUEST_URI} ^system.*
  RewriteRule ^(.*)$ /index.php/$1 [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

this rewrite rule make

Code:
base_url/index.php/stocks/bycategory/9

become

Code:
base_url/stocks/bycategory/9.html

but i want more advance, i want to replace ID become category name.
for example become like this

Code:
base_url/stocks/bycategory/pants.html
or
Code:
base_url/stocks/bycategory/shirts.html
etc

Could anyone help me to solve this problem...?
Smile
#2

[eluser]Pascal Kriete[/eluser]
You probably wouldn't want the htaccess file to do that, or you would need to change the file every time you add/remove a category.

Instead, I would suggest adding a db column for your categories that holds the url title name. Then you can look it up using that name instead of the id. The url helper has a url_title function that can help you generate a url safe string from any given title.

Make sense?
#3

[eluser]sihijau[/eluser]
hehe.. Smile
thanks for your solution..
i'll try.




Theme © iAndrew 2016 - Forum software by © MyBB